Skip to content

CSS Box Shadow Generator

Build one box-shadow declaration from offsets, a blur, a spread, and a color. 4, 8, 16, 0, and #000000 becomes box-shadow: 4px 8px 16px 0px #000000;. The page does not apply it to a stylesheet.

Result

Enter the shadow values

How to Use

  1. 1 Enter the horizontal offset, the vertical offset, the blur, and the spread.
  2. 2 Enter a hex color, or click a color in the palette.
  3. 3 Copy the declaration. 4, 8, 16, 0, and #000000 is the sample.

Example Output

  • 4, 8, 16, 0, and #000000 is box-shadow: 4px 8px 16px 0px #000000;.

About This Tool

Horizontal and vertical offsets may be negative. Blur and spread may not. The color is a #RGB or #RRGGBB value.

Using the CSS Box Shadow Generator

This page writes one CSS declaration. The sample horizontal offset is 4, the vertical offset is 8, the blur is 16, the spread is 0, and the color is #000000. The declaration is box-shadow: 4px 8px 16px 0px #000000;. The headline is that declaration, and the line under it repeats the same CSS. Each length is printed with px. The color is printed last, after the page has lowercased a valid hex value.

Horizontal and vertical offsets are whole numbers from -200 to 200. Blur and spread are whole numbers from 0 to 200. A negative blur or a negative spread is rejected. Color must be #RGB or #RRGGBB. A named color, a short hex without the hash, and an eight-digit hex are rejected with the message that color must be a #RGB or #RRGGBB hex value. The page does not write a stylesheet, does not attach the declaration to an element, and does not invent a second shadow.

The order is fixed: horizontal, vertical, blur, spread, color. Swapping blur and spread in your head will not match the declaration, because the page always prints them in that order from the fields you filled. A spread of 0 is still printed. The sample includes 0px rather than omitting the spread.

Copy the declaration if you want it in a rule you maintain elsewhere. Changing a field and calculating again replaces the declaration. The page does not keep a list of earlier shadows.

What the Declaration Includes

The sample string is box-shadow: 4px 8px 16px 0px #000000; including the colon, the spaces, the px units, and the final semicolon. There is no inset keyword, no comma, and no second color. The headline and the CSS line are the same text, so a mismatch between them would mean you are looking at a note you edited, not at the page. The four numbers and the color are the entire input.

How the Five Fields Are Ordered

Under the color field, a palette shows a variety of colors, each in its own box. Click a box and that hex is written into the field. You can still type a different hex. The page reads the horizontal offset, then the vertical offset, then the blur, then the spread, then the color. It checks each number against its bounds and checks the color against the hex pattern. It lowercases the hex. #000000 stays #000000. #ABC becomes #abc. It then places px after each of the four numbers and joins them with single spaces. The property name and the semicolon are constant. Nothing in that join looks at a stylesheet you already have. The fields are the only source. If a rule in a file already says something else, this page will not merge with it. You copy the new declaration over, or you leave the file alone. Calculating a second time with the same five values repeats the same string, including the px units and the lowercase hex. That repeat is how you know the join did not drift.

A flex container is a different declaration. The CSS Flexbox Generator builds flex rules from the choices on that form. Row, flex-start, stretch, and a gap of 16 becomes its sample CSS. That page does not write a stylesheet either, and it does not emit box-shadow. Use it when you are describing a flex container. Use this page when you are describing one shadow.

Offsets, Blur, and Spread Stay Separate

Horizontal and vertical offsets may be negative, down to -200. A negative horizontal value is a shadow to the left if you later apply the declaration in the usual way. A negative vertical value is a shadow upward in that same usual reading. The page does not draw the box, so those directions are a reading of the numbers, not a picture it renders. Blur and spread cannot be negative here. A blur of 0 is sharp. A spread of 0 adds no extra spread beyond the offsets and the blur.

Declarations from Nearby Numbers

Enter 4, 8, 16, 0, and #000000. Read box-shadow: 4px 8px 16px 0px #000000;. Change only the horizontal offset to -4. The declaration begins box-shadow: -4px 8px 16px 0px #000000;. Change only the spread to 2 and restore the horizontal offset to 4. The declaration is box-shadow: 4px 8px 16px 2px #000000;. Change the color to #ABC. The declaration ends in #abc. Change the blur to 0. The declaration contains 0px in the blur position and 0px in the spread position if spread is also 0, and both zeros remain. The two zeros are not a glitch. They are the two fields, printed in order, blur first and spread second. If you need to tell them apart, change only the spread to 1 and watch the fourth length change while the third stays 0px. Then put the spread back to 0 before you treat the result as the sample.

Equal columns are a different piece of CSS. The CSS Grid Generator builds a grid container with equal columns. Three columns and a gap of 16 becomes repeat(3, 1fr) and gap 16px. That page does not write a stylesheet, and it does not build a box-shadow declaration. Use it for the grid. Use the five fields here for the shadow.

Whole Numbers and a Hex Color Only

An offset that is not a whole number from -200 to 200 is rejected. The horizontal message says the horizontal offset must be a whole number from -200 to 200. The vertical message says the same for the vertical offset. Decimals are rejected. 4.5 is not a whole number on this form. Values of -200 and 200 are accepted. Values of -201 and 201 are rejected.

Mistakes that Scramble the Shadow

Typing the blur into the spread field prints a wide shadow with no blur, or the reverse. The sample wants 16 in blur and 0 in spread. If the declaration shows 4px 8px 0px 16px, the fields were swapped. Another miss is to omit px in a hand copy and then wonder why it does not match. The page always writes px. Another miss is to expect the page to drop a zero spread. It will not. Another miss is to paste a color with a leading space that you think is part of the value. The field is trimmed, so a surrounding space is removed before the hex test. A space in the middle of the hex still fails. Another miss is to type the color with a css function wrapped around it. The field wants the hash form only. Another miss is to read 16px as the spread because it is a larger number than 0. In the sample, 16px is the third length, which is the blur. The fourth length is the spread, and the sample prints 0px there on purpose so the position is visible.

A recolored hex is a different tool. The Color Blindness Simulator recolors one hex value with a published simulation matrix. The result is an approximation of the typed color, not a diagnosis and not a test of a person's vision. This page does not recolor #000000. It places the hex you typed, lowercased, at the end of the declaration.

Pasting the Declaration into Your Own Rule

Copy the whole declaration, including box-shadow and the semicolon. A note that keeps only 4px 8px 16px 0px #000000 has the values and has lost the property name. Put the declaration inside a rule you control. This page will not name a selector for you. If you need two shadows, run the page twice and join the declarations yourself with a comma in your stylesheet. The page emits one shadow per calculation.

Rebuilding the Sample Declaration

Write box-shadow: then a space. Write 4px, space, 8px, space, 16px, space, 0px, space, #000000, and a semicolon. Compare that string with the headline. They should match character for character, including the zeros and the hash. Then rebuild a negative case. Horizontal -4 produces -4px in the first length and leaves the rest of the sample alone. Then rebuild a three-digit color. #ABC is accepted and printed as #abc, still in the last position. The lowercase is part of the match. If your hand copy still says #ABC, it has the right digits and the wrong case relative to the page. The page lowercases after it accepts the hex. #000000 does not show the change because those digits are already lowercase. Use #ABC when you want to see the case change happen.

Minified JSON is a different cleanup. The JSON Minifier removes insignificant space from a JSON value. {"a": 1} becomes {"a":1}. It parses the text first, so a broken value is rejected instead of being trimmed by hand. A box-shadow declaration is not JSON. Do not expect the minifier to validate this CSS. Use it for a JSON value. Use the five fields here for the shadow string.

Reading Each Length in Its Place

Cover the headline and predict it from the fields. Horizontal, vertical, blur, spread, color, each length with px, color untouched except for case. Uncover the headline and compare. Then set every numeric field to 0 and the color to #000000. The declaration is box-shadow: 0px 0px 0px 0px #000000;. Four zeros are legal. Then set blur to 200 and spread to 200, with offsets at 200. Those bounds are accepted. Set blur to 201 and confirm the rejection. Set the color to #gg0000 and confirm the hex rejection. Return to 4, 8, 16, 0, and #000000.

Checking the Generator

Enter 4, 8, 16, 0, and #000000. Confirm box-shadow: 4px 8px 16px 0px #000000;. Enter a horizontal offset of -200 and confirm it is accepted. Enter 201 and confirm the range rejection. Enter a blur of -1 and confirm the rejection. Enter #abc and confirm the declaration ends in #abc. Enter the word black and confirm the hex rejection. Calculate the sample again so the visible declaration is the original one. Read the four lengths in order and the color last. 4px, 8px, 16px, 0px, #000000. If the third length is not 16px, the blur field is not the sample. If the color is not #000000, the color field is not the sample. The property name and the semicolon should still frame the whole line.

Changing the case of ordinary words is a different page. The Uppercase Converter turns the text you type into upper case. hello becomes HELLO. It does not change any other case, and it does not build a box-shadow declaration. This page lowercases a valid hex color as part of writing the declaration. Use the uppercase page for text you want in capitals. Use the shadow fields for the CSS.

Frequently Asked Questions

What do horizontal 4, vertical 8, blur 16, spread 0, and color #000000 return?

box-shadow: 4px 8px 16px 0px #000000;

What are the offset bounds?

Horizontal and vertical offsets are whole numbers from -200 to 200.

What are the blur and spread bounds?

Both are whole numbers from 0 to 200. Negatives are rejected.

Which colors are accepted?

A #RGB or #RRGGBB hex value. The page lowercases it. Named colors are rejected.

Does a spread of 0 disappear from the declaration?

No. The sample includes 0px before the color.

Does the page write a stylesheet?

No. It returns the declaration for you to copy.

Can the page emit two shadows?

No. One calculation is one declaration. Join two results yourself if you need a list.

What does #ABC become?

#abc, in the color position of the declaration.

Are decimals allowed on the offsets?

No. Offsets, blur, and spread must be whole numbers.

Does the page add inset or transparency?

No. The declaration is four lengths in px and one hex color.

What does a horizontal offset of -4 change in the sample?

The declaration begins box-shadow: -4px 8px 16px 0px #000000; when the other fields stay at 8, 16, 0, and #000000. Only the first length changes sign.