PX سے REM کنورٹر

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

rem قدریں بنیادی فونٹ سائز کے نسبت ہوتی ہیں، جو ہر براؤزر میں 16px ہوتا ہے جب تک کوئی اسٹائل شیٹ اسے نہ بدلے۔ نتائج چار اعشاریوں تک گول کیے جاتے ہیں اور آخری صفر ہٹا دیے جاتے ہیں۔

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

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

جتنی چاہیں قدریں چسپاں کریں، خالی جگہ، کوما، سیمی کولن یا نئی سطر سے جدا کر کے، اور ہر ایک جدول کی ایک سطر میں بدل جاتی ہے۔ قدر کے آخر میں لگا ہوا px یا rem عدد پڑھنے سے پہلے ہٹا دیا جاتا ہے، اس لیے آپ سیدھا اسٹائل شیٹ سے چسپاں کر سکتے ہیں۔ جو اندراج عدد نہ ہوں انہیں پورے بیچ کو ناکام کرنے کے بجائے چھوڑ کر گن لیا جاتا ہے، اور پہلی پانچ سو قدریں تبدیل ہوتی ہیں۔

جڑ کا سائز چننا، اور جاننا کہ rem کہاں لاگو نہیں ہوتا

  • ہر بڑے براؤزر میں طے شدہ جڑ سائز 16px ہے: جب تک آپ نے اسے جان بوجھ کر نہ بدلا ہو، یہی وہ عدد ہے جس کے حساب سے تبدیلی کرنی ہے۔ جڑ کو 62.5% کر کے 1rem کو 10px کے برابر کرنا آسان حساب کے بدلے ایسی اسٹائل شیٹ دیتا ہے جو اس ایک قاعدے کے ہٹتے ہی ٹوٹ جاتی ہے۔
  • نتائج چار اعشاریہ مقامات تک گول کیے جاتے ہیں: جو کسی بھی اسکرین کی نمائشی صلاحیت سے کہیں زیادہ باریک ہے۔ اگر آپ کو پڑھنے میں آسان اعداد چاہئیں تو اپنی اسٹائل شیٹ میں مزید گول کر لیں؛ بصری فرق صفر ہے۔
  • میڈیا کوئری واحد جگہ ہے جہاں rem آپ کی جڑ کے تابع نہیں: کوئری آپ کے مقرر کردہ جڑ فونٹ سائز کے بجائے براؤزر کے ابتدائی فونٹ سائز کے حساب سے طے ہوتی ہے، اس لیے جڑ بدلنے سے آپ کے بریک پوائنٹ نہیں ہلتے۔
  • ہر لمبائی بدلنے کے قابل نہیں: کنارے، باریک لکیریں اور ہر وہ چیز جسے مقررہ طبیعی سائز پر رہنا ہے، پکسل میں بہتر پڑھی جاتی ہے۔ متن، وقفے اور ڈبوں کی چوڑائی کو بڑھنے دیں؛ ایک پکسل کی لکیر کو ایک پکسل ہی رہنے دیں۔

The division is not the point

Converting pixels to rem is one division, and nobody needs help with it. The reason it is worth doing at all is what the divisor means.

A rem is the font size of the root element — which is to say, whatever the reader has set their browser to. Someone who has increased their default text size because they need to gets a layout that grows with them. The same layout written in pixels ignores that person completely. That is the accessibility argument, and it is the entire case for the unit.

The [msm_tool slug="px-to-rem"] converts in batches against whatever root you specify, which matters when you are migrating an existing stylesheet rather than starting fresh.

16px is the number

Every major browser defaults its root font size to 16 pixels. Unless your stylesheet deliberately sets something else, that is the figure to convert against.

You will find advice to set the root to 62.5%, making 1rem equal 10px so the arithmetic is trivial. It works, and it trades easy mental maths for a stylesheet that breaks entirely if that one rule is ever removed or overridden. It also means every rem value in your codebase is meaningless without knowing about the trick. Most teams that adopt it eventually regret it.

What to convert, and what to leave

Not every length should scale with the reader's text size.

  • Convert: font sizes, line heights, padding and margins around text, container widths, gaps between elements. Anything whose job is to give text room to breathe should grow when the text does.
  • Leave in pixels: borders and hairlines, box-shadow blur radii in most cases, and anything meant to stay a fixed physical size. A one-pixel rule should stay one pixel; scaling it to 1.0625 pixels helps nobody.
  • Consider neither: some values are better as percentages or viewport units. A full-bleed section is 100vw, not a converted pixel value.

rem and em are not interchangeable

A rem is always relative to the root. An em is relative to the font size of its own element, which means ems compound as they nest.

Set a list item to 0.9em and nest three levels of lists, and the innermost is at 0.73 of the base without anyone intending it. That compounding is occasionally exactly what you want — padding inside a button expressed in em scales automatically with the button's own font size, which is genuinely useful — but it is a deliberate choice rather than a default.

The rule of thumb: rem for anything that should relate to the page, em for anything that should relate to its own element's text.

Media queries do not use your root

This one surprises people. A rem inside a media query resolves against the browser's initial font size, not the root font size you set in your stylesheet.

So if you set the root to 62.5% and then write @media (min-width: 48rem), that breakpoint is at 768 pixels, not 480. Changing the root does not move your breakpoints, and expecting it to is a reliable source of layouts that break at the wrong widths.

Rounding

The converter reports four decimal places, which is far finer than any screen can render. Round further in your stylesheet if you prefer readable numbers — the visual difference between 1.4375rem and 1.44rem is nothing.

Where it does matter is consistency. Rounding some values and not others produces a scale that drifts, and a type scale that is nearly-but-not-quite proportional looks worse than one that is obviously stepped.

Migrating an existing stylesheet

Converting everything at once rarely goes well. A workable order:

  1. Font sizes first. They are the highest value and the easiest to verify by eye.
  2. Then vertical spacing — margins and padding above and below text. This is where the benefit shows: text that grows without its surrounding space growing looks cramped.
  3. Then container widths. Test at increased browser text size before and after; this is the step that reveals layouts assuming a fixed character count per line.
  4. Leave borders, shadows and decorative sizes alone unless you find a reason.

Test by setting your browser's default font size to 20 or 24 pixels and using the site. That is the check the conversion exists to pass, and it is the one nobody runs.

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

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

سولہ پکسل، جو براؤزر کا طے شدہ سائز ہے۔ اسی کے حساب سے تبدیلی کریں، الا یہ کہ آپ کی اسٹائل شیٹ جان بوجھ کر کوئی اور جڑ مقرر کرتی ہو، تو پھر اپنی والی لیں۔
کیونکہ جس قاری نے اپنے براؤزر کا متن سائز بڑھایا ہے، اسے پکسل میں لکھے لے آؤٹ سے کوئی فائدہ نہیں ملتا۔ rem میں لکھی لمبائیاں اس ترتیب کے ساتھ بڑھتی ہیں۔
جی ہاں۔ انہیں خالی جگہ، کوما، سیمی کولن یا نئی سطر سے جدا کریں۔ آخر میں لگا px یا rem نظر انداز ہو جاتا ہے، اس لیے سیدھا اسٹائل شیٹ سے چسپاں کرنا کام کرتا ہے۔
rem ہمیشہ جڑ عنصر کے تابع ہوتا ہے۔ em اپنے ہی عنصر کے فونٹ سائز کے تابع ہوتا ہے، اس لیے em ایک دوسرے کے اندر آ کر ضرب کھاتے چلے جاتے ہیں اور rem ایسا نہیں کرتے۔
قبول تو ہوتے ہیں، مگر وہ آپ کی جڑ کے بجائے براؤزر کے ابتدائی فونٹ سائز کے حساب سے طے ہوتے ہیں، اس لیے جڑ بدلنے سے آپ کے بریک پوائنٹ نہیں ہلیں گے۔

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