الترميز
HTML Entities Encode/Decode
ترميز وفك ترميز كيانات HTML — عرض آمن للأحرف الخاصة في الصفحة.
HTML entities are a way to write characters that would otherwise break markup (<, >, &) or have no keyboard key, as safe text sequences like < or &. This tool encodes and decodes such entities right in your browser.
How to use it
- Encode: paste text and characters like <, >, &, and quotes get replaced with their matching entities.
- Decode: paste HTML containing entities (&, ©, etc.) to see the plain text.
- Both named entities (&) and numeric ones (& or &) are supported.
Common uses
- Safely displaying user text (a comment, a message) on a page without risking broken markup or an injected script.
- Embedding HTML code samples in an article or documentation so the browser shows them as text instead of rendering them.
- Decoding content copied from another site where the characters arrived already entity-encoded.
Things to keep in mind
HTML entity escaping only protects against XSS via a page's text content — it does not protect a JavaScript context (innerHTML, eval) or href/src attributes containing unvalidated URLs.
Encode exactly at the point where text gets inserted into HTML, not ahead of time when saving to a database — otherwise the data gets mangled when reused outside an HTML context.
مقالة عن هذه الأداة: HTML Entities: كيف تعرض الأحرف الخاصة بأمان
الأسئلة الشائعة
ما الفرق بين الكيانات المسمّاة والكيانات الرقمية في HTML؟
الكيان المسمّى مثل & يستخدم اسمًا مختصرًا سهل القراءة، بينما الكيان الرقمي مثل & أو & يشير إلى الحرف عبر رمزه العددي (عشري أو سداسي عشري). كلاهما يُعرَض بنفس الطريقة في المتصفح.
لماذا أحتاج لترميز الأحرف الخاصة قبل عرضها في صفحة HTML؟
لأن أحرفًا مثل < و> و& لها معنى خاص في بنية HTML، فإذا وُضعت كما هي في المحتوى قد يفسّرها المتصفح كوسم أو كود بدلًا من نص عادي، مما يكسر الصفحة أو يفتح ثغرات مثل XSS.
ما الفرق بين وضعي "أساسية" و"جميع الأحرف"؟
الوضع الأساسي يرمّز فقط الأحرف الحرجة لبنية HTML مثل < و> و& وعلامات الاقتباس، بينما وضع جميع الأحرف يحوّل أيضًا الأحرف غير ASCII إلى كياناتها المقابلة إن وُجدت.
هل يجب الهروب من النص داخل سمة (attribute) بطريقة مختلفة عن نص الصفحة؟
الأحرف الأساسية (<، >، &) تُهرَب بنفس الطريقة، لكن داخل سمة محاطة بعلامات اقتباس يصبح من الضروري أيضًا الهروب تحديدًا من نوع علامة الاقتباس المستخدم لإحاطة السمة — وإلا "تنكسر" القيمة قبل الأوان.
هل يحمي الهروب من أحرف HTML من جميع أنواع XSS؟
لا. فهو يسدّ أشيع المسارات — إدراج نص داخل محتوى HTML — لكنه لا يحمي من XSS عبر سياق JavaScript (مثل استخدام innerHTML مع تنفيذ كود لاحق) أو عناوين URL غير المُتحقَّق منها في href أو src.