CSS باکس شیڈو بلڈر

استعمال کا طریقہ 3 مراحل
  1. افقی فاصلہ X، عمودی فاصلہ Y، دھندلاہٹ کا رداس اور پھیلاؤ طے کریں۔
  2. سائے کا رنگ اور دھندلاہٹ چنیں؛ اندرونی سائے کے لیے Inset پر نشان لگائیں۔
  3. Shadow CSS کاپی کریں دبائیں اور اپنی اسٹائل شیٹ میں چسپاں کریں۔
Box Shadow پیش منظر خانہ
تیار کردہ CSS کوڈ

یہ ٹول کیسے کام کرتا ہے

box-shadow چار لمبائیاں اور ایک رنگ لیتا ہے: کتنا دائیں، کتنا نیچے، کنارہ کتنا نرم ہو، اور سایہ اس سب سے پہلے کتنا بڑھے یا سکڑے۔ پہلی دو اسے جگہ دیتی ہیں، دھندلاہٹ طے کرتی ہے کہ وہ صاف کنارے کی طرح پڑھا جائے یا پھیلی ہوئی چمک کی طرح، اور پھیلاؤ وہ ہے جسے زیادہ تر لوگ کبھی چھوتے نہیں، حالانکہ یہی چست جدید سائے کو پھولے ہوئے سائے سے جدا کرتا ہے۔

رنگ اور دُھندلاہٹ کو الگ رکھنے کے بجائے یہاں ایک rgba قدر میں ملا دیا جاتا ہے، کیونکہ پوری شدت کا سایہ تقریباً کبھی سائے جیسا نہیں لگتا۔ اصل سائے روشنی کی غیر موجودگی ہوتے ہیں، سیاہ رنگ کی تہہ نہیں، اس لیے عام غلطی کم کے بجائے زیادہ دُھندلاہٹ ہے۔ inset آن کرنے سے پوری چیز عنصر کے اندر چلی جاتی ہے، اور دبے ہوئے یا دھنسے ہوئے کنٹرول اسی طرح بنائے جاتے ہیں۔

ایسا سایہ بنانا جو روشنی جیسا لگے

  • فاصلے کو ایک ہی منبعِ روشنی سے ملائیں: اگر ایک عنصر اپنا سایہ نیچے اور دائیں ڈالتا ہے تو صفحے کے باقی سب عناصر کو بھی ایسا ہی کرنا چاہیے۔ ملی جلی سمتیں انٹرفیس کو ٹکڑوں سے جوڑا ہوا دکھانے کا تیز ترین طریقہ ہیں۔
  • بڑے عناصر کو بڑے اور نرم سائے چاہیے: صفحے سے اٹھا ہوا کارڈ بٹن سے بڑی دھندلاہٹ اٹھاتا ہے۔ دھندلاہٹ اور فاصلے کو چیز کے حجم کے ساتھ بڑھانا ہی بلندی کو یکساں محسوس کراتا ہے۔
  • اکیلا سایہ شاذ ہی بہترین ہوتا ہے: یہ خصوصیت کوما سے جدا فہرست لیتی ہے، اور دو سائے — ایک تنگ اور گہرا برائے چھوہ، ایک چوڑا اور مدھم برائے ماحول — کسی ایک سے کہیں زیادہ قائل کرتے ہیں۔
  • پھیلاؤ منفی بھی ہو سکتا ہے: منفی پھیلاؤ سائے کو عنصر سے بھی تنگ کھینچ لیتا ہے، جو ایسی ہلکی سی بلندی کے لیے کارآمد ہے جو کناروں سے باہر نہ پھیلے۔

Four numbers and a colour

A box shadow takes a horizontal offset, a vertical offset, a blur radius and a spread, plus a colour. The first two place it, the blur decides whether it reads as a crisp edge or a diffuse glow, and the spread grows or shrinks the shadow before any of that is applied.

Spread is the one most people never touch, and it is what separates a tight modern shadow from a puffy one. A negative spread pulls the shadow in tighter than the element, which gives a subtle lift that does not bleed out around the edges. The [msm_tool slug="box-shadow"] exposes all four along with the opacity, which is the fifth thing that decides whether a shadow looks like light or like paint.

Why most shadows look wrong

Almost always too much opacity, too little blur, or both.

A real shadow is the absence of light, not a layer of black. Pure black at 50% opacity on a white background produces a grey rectangle that reads as a graphic element rather than as depth. Start lower than feels right — ten to fifteen percent — and increase the blur until the edge stops being a line.

The second common fault is tinting. A shadow on a coloured surface picks up that surface's hue in reality, and a pure black shadow on a warm background looks slightly dead. Shifting the shadow colour toward the background's hue, or toward a deep blue on a neutral page, reads as more natural than black at the same opacity.

One light source for the whole page

If one element casts its shadow down and to the right, every other element should too. Mixed directions are the fastest way to make an interface look assembled from parts by different people.

Most interfaces settle on a light source directly above, meaning zero horizontal offset and a positive vertical one. It is the least distracting choice and it scales cleanly: to make something look higher off the page, increase the vertical offset and the blur together rather than adding a horizontal shift.

Elevation is a scale, not a value

Rather than choosing a shadow per component, define three or four and use them consistently. A common set:

  • Resting — a very small offset and blur, for cards and inputs that sit on the page.
  • Raised — larger, for elements that have been hovered or focused.
  • Floating — larger again, for dropdowns and popovers that overlay content.
  • Modal — largest, for dialogs that sit above everything.

Larger elements need larger, softer shadows. A card lifted off the page carries a bigger blur than a button at the same conceptual elevation, and scaling blur and offset together with the size of the thing is what makes the levels read as consistent rather than arbitrary.

Two shadows beat one

The property takes a comma-separated list, painted back to front, and this is where the convincing results come from.

Real objects cast two distinguishable shadows: a tight dark one where the object nearly touches the surface, and a wide faint one from ambient light. One tight shadow with a small offset and low blur, plus one wide shadow with a larger offset and much larger blur at a lower opacity, looks considerably more like depth than either alone. Nearly every well-regarded design system does this.

inset, and what it is for

The inset keyword moves the shadow inside the element. That is how pressed buttons, recessed panels and inner glows are drawn, and it is also the honest way to show a form field as sunken rather than raised.

A note on pressed states: an inset shadow alone is a weak signal. Pair it with a small downward shift of the content, or a background change, so the state is not carried by a single soft edge.

Performance

Small shadows on a handful of elements cost nothing worth measuring. Two things do cost:

  1. Large blurs on many elements. The cost grows with the blur radius and the number of elements repainting. A long list where every row carries a heavy shadow will feel less smooth than the same list without.
  2. Animating the shadow itself. Transitioning box-shadow forces a repaint on every frame. The usual technique is to put the larger shadow on a pseudo-element and transition its opacity, which the browser can handle on the compositor without repainting.

When not to use one

A shadow's job is to say that something sits above the surface. If everything on a page has one, nothing does — the hierarchy flattens and the page reads as noisy.

Borders, background changes and spacing often separate elements more clearly and more cheaply. Reserve shadows for the things that genuinely are floating: menus, dialogs, sticky headers, and cards you want to read as pickable.

اکثر پوچھے گئے سوالات

خاص طور پر CSS باکس شیڈو بلڈر کے بارے میں۔ اس زمرے سے متعلق عمومی سوالات کے جواب زمرے کے صفحے پر موجود ہیں۔

دھندلاہٹ کنارے کو نرم کرتی ہے مگر سائے کا حجم نہیں بدلتی۔ پھیلاؤ دھندلاہٹ سے پہلے حجم بدلتا ہے، اس لیے مثبت قدر سائے کو عنصر سے بڑا کر دیتی ہے۔
تقریباً ہمیشہ بہت زیادہ دُھندلاہٹ، بہت کم بلر، یا دونوں۔ سایہ غیر موجود روشنی ہے، رنگی ہوئی تہہ نہیں — کم سے شروع کریں اور تب تک بڑھائیں جب تک وہ بمشکل نظر آنے لگے۔
یہ سایہ عنصر کے پیچھے کے بجائے اس کے اندر بناتا ہے، اور دبے ہوئے بٹن، دھنسے ہوئے پینل اور اندرونی چمک اسی طرح بنتے ہیں۔
جی ہاں۔ یہ خصوصیت کوما سے جدا فہرست لیتی ہے جو پیچھے سے آگے بنتی ہے۔ دو — ایک تنگ، ایک چوڑا اور مدھم — ایک سے کہیں بہتر پڑھے جاتے ہیں۔
بڑے دھندلے سائے مہنگے ہیں، خاص طور پر جب متحرک ہوں یا ایک ساتھ کئی عناصر پر ہوں۔ چند عناصر پر چھوٹا سایہ کوئی قابلِ ذکر قیمت نہیں رکھتا۔

نئے ٹولز، خصوصیات اور کارکردگی بڑھانے کے مشوروں کی اطلاع پانے کے لیے سبسکرائب کریں۔