CSS بٹن اسٹائل جنریٹر

استعمال کا طریقہ 3 مراحل
  1. بٹن کا عنوان لکھیں اور رنگ اور انداز چنیں۔
  2. حروف کی موٹائی، کونے کا رداس اور پیڈنگ طے کریں۔
  3. ہوور کی حالت جانچنے کے لیے پیش منظر پر ماؤس لائیں، پھر بٹن CSS کاپی کریں دبائیں۔
تیار کردہ CSS کوڈ

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

بٹن ظاہری وضع سے زیادہ حالتوں کا معاملہ ہے۔ ٹھہری ہوئی وضع آسان حصہ ہے؛ جو چیز اسے قابلِ استعمال بناتی ہے وہ یہ ہے کہ وہ اشارہ کرنے والے کو نظر آنے والا جواب دے، اور یہ کہ کی بورڈ سے صفحے میں چلنے والا شخص دیکھ سکے کہ وہ کہاں ہے۔ دونوں یہاں بنیادی اصول کے ساتھ بنائے جاتے ہیں، کیونکہ صرف ٹھہری ہوئی حالت والی بٹن کی وضع ہی وہ چیز تھی جو یہ ٹول پہلے دیتا تھا اور وہی وجہ تھی کہ اس کا نتیجہ جوں کا توں استعمال نہیں ہو سکتا تھا۔

عنوان کا رنگ سفید فرض کرنے کے بجائے بھرائی کی نسبتی چمک سے چنا جاتا ہے، کیونکہ ہلکی بھرائی پر سفید عبارت بنائے گئے بٹن کے CSS میں سب سے عام ناکامی ہے۔ hover کا رنگ بھرائی کو سیاہ یا سفید کی طرف کھسکا کر نکالا جاتا ہے، اس سمت میں جہاں گنجائش ہو۔ focus-visible کا حلقہ hover سے جان بوجھ کر الگ ہے: یہ کی بورڈ استعمال کرنے والوں کے لیے ظاہر ہوتا ہے اور محض کلک کرنے والے کسی شخص کے لیے نہیں۔

بٹن کو کیا چیز کارآمد بناتی ہے

  • focus کا خاکہ کبھی بغیر متبادل کے نہ ہٹائیں: outline: none اور اس کی جگہ کچھ نہ ہونا صفحے کو کی بورڈ سے ناقابلِ استعمال بنا دیتا ہے، اور یہ ویب پر رسائی کی سب سے عام خرابی ہے۔
  • focus-visible جدید سلیکٹر ہے: یہ کی بورڈ سے چلنے پر حلقہ دکھاتا ہے اور ماؤس کے کلک پر چھپا دیتا ہے، اور لوگ جب خاکے سرے سے ہٹا دیتے تھے تو یہی حاصل کرنا چاہتے تھے۔
  • چھونے کے نشانے تقریباً 44 پکسل چاہتے ہیں: وقفہ اور عبارت کا سائز مل کر نشانہ طے کرتے ہیں۔ جو بٹن ڈیسک ٹاپ پر کشادہ لگے وہ پھر بھی چھونے میں بے ڈھنگا ہو سکتا ہے۔
  • سایہ دار وضع کو کہیں نہ کہیں نظر آنے والی حد چاہیے: ٹھہری حالت میں نہ پس منظر نہ بارڈر، تو یہ صرف اپنے عنوان پر انحصار کرتی ہے۔ ٹھوس بٹن کے پہلو میں ثانوی عمل کے لیے ٹھیک ہے، اسکرین پر اکیلے بٹن کے طور پر کمزور۔

A button is mostly states

The resting style is the easy part and the part everyone designs. What makes a button usable is that it visibly responds to a pointer, and that someone moving through the page by keyboard can see where they are.

That is why the [msm_tool slug="css-button-generator"] emits a hover rule and a :focus-visible rule alongside the base one. A button style that covers only the resting state is not finished; it is a rectangle.

focus-visible, and why it exists

For years the pattern was outline: none, because the default focus ring appeared on mouse clicks and looked untidy. The cost was that keyboard users lost any indication of where they were, which makes a page unusable rather than untidy.

:focus-visible resolves it properly. The browser applies it when it judges that a visible indicator is needed — keyboard navigation yes, mouse click no. That is what people were actually trying to achieve when they removed outlines, and it has been supported everywhere current for years.

Two rules follow from that:

  1. Never remove a focus indicator without replacing it. This is the most common accessibility fault on the web, and it is the one with the clearest consequence: a whole category of user cannot operate the page.
  2. Give the replacement real contrast. A focus ring is a non-text interface element and is held to 3:1 against its surroundings. A pale ring on a pale background is present and useless.

An outline-offset of a couple of pixels keeps the ring clear of the button's own edge, which matters on rounded shapes where a tight outline looks like a rendering error.

The label colour is not always white

Generated button CSS defaults to white text with striking regularity, and it fails the moment the fill is light. A yellow button with white text is unreadable and very common.

The generator chooses the label colour from the fill's relative luminance instead: light fills get a dark label, dark fills get a white one. It is a small thing that removes an entire class of mistake, and it is worth doing by hand if your own system does not.

Touch targets

Around 44 pixels in each direction is the widely used minimum, and it comes from padding and font size together rather than from a height you set.

A button that looks generous on a desktop can still be an awkward tap, particularly a text button with tight vertical padding. If the design demands a visually small button, the trick is to keep the visible size and extend the hit area with padding on a wrapper or a pseudo-element.

Solid, outline and ghost

  • Solid — the primary action. One per view, ideally. A screen with four solid buttons has no primary action.
  • Outline — secondary actions beside a solid one. Visible boundary, lower weight.
  • Ghost — tertiary. No background and no border at rest, so it depends entirely on its label. Fine next to something stronger; weak as the only button on a screen, because there is nothing to aim at until you find the words.

The hover state matters most for ghost and outline, since at rest they give the least indication of being interactive.

Deriving the hover colour

Shifting the fill toward black or white by a fixed amount is the usual approach, and the direction should depend on the fill: darken a light colour, lighten a dark one. Doing it in one direction always produces a hover state that disappears on half your palette.

Keep the change modest. A hover that changes the colour dramatically reads as a different button rather than the same button responding.

Buttons and links are not interchangeable

Worth stating because CSS makes them look identical.

A <button> performs an action; an <a> navigates somewhere. They behave differently under the keyboard — space activates a button, enter activates a link — and they are announced differently by screen readers. Styling a link to look like a button is fine; using a <div> with a click handler is not, because it has no role, no keyboard behaviour and no focus by default.

The disabled state

Disabled controls are exempt from the contrast minimum, which is why they can be washed out. That exemption is not a licence to make them indistinguishable from enabled ones — if a user cannot tell which buttons work, the low contrast has caused a different problem.

Better still, where possible, is to leave the button enabled and explain what is missing when it is pressed. A disabled button with no explanation is a dead end.

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

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

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

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