Interview Question

What is pattern attribute?

Pattern checks text against a simple rule.

💡 Concept ✅ Quick Revision 🌐 HTML

Answer

The `pattern` attribute adds a text pattern that a form value must match. β€’ It is written inside an element’s opening tag. β€’ The HTML Standard limits which elements may use it and which values are valid. β€’ Browsers apply the attribute when they process the element or the resource it controls.

💡 Simple Example

<input pattern="[0-9]{4}" title="Enter four digits">

⚡ Quick Revision

Pattern checks text against a simple rule.