HTML Elements and Tags
HTML Elements और Tags
Anatomy of an Element — three parts
<p> Alpine Public School </p>
│ │ │
opening content closing
tag tag
/). The complete sandwich — all three together — is called an element.Tag vs Element — the interview one-liner
| Tag | Element | |
|---|---|---|
| What | Just the bracket part: <p> or </p> | Opening tag + content + closing tag (the whole thing) |
| Example | <h1> | <h1>Welcome</h1> |
| Analogy | One slice of bread | The complete sandwich |
Empty (Self-Closing / Void) Elements — no closing tag
Some elements have no content to sandwich, so they have no closing tag at all:
<br> line break
<hr> horizontal line
<img src="a.jpg" alt="..."> image
<input type="text"> form field
<meta charset="UTF-8"> page info
<link rel="stylesheet"> CSS attach
Writing <br/> with a slash is also valid (an old XHTML habit) — both <br> and <br/> work in HTML5. But <br></br> is wrong — a void element never takes a closing tag.
Case Sensitivity — lowercase always
<P>Works but looks amateur</P>
<p>Professional standard</p>
HTML tags are not case-sensitive — <P> and <p> both render. But the universal convention (and XHTML/JSX requirement) is lowercase everywhere. Build the habit now; frameworks you meet later will demand it.
Exam Corner
Q: What happens if you forget a closing tag? The browser guesses where it should end — sometimes right, sometimes swallowing the rest of the page into that element. Bold text running to the bottom of the page = an unclosed <b> somewhere above.
Q: Is <br></br> valid? No — void elements never have closing tags. <br> or <br/> only.
Element की बनावट — तीन हिस्से
<p> Alpine Public School </p>
│ │ │
opening content closing
tag tag
/ के साथ). पूरा sandwich — तीनों मिलाकर — element कहलाता है.Tag vs Element — interview की one-liner
| Tag | Element | |
|---|---|---|
| क्या | सिर्फ bracket वाला हिस्सा: <p> या </p> | Opening tag + content + closing tag (पूरी चीज़) |
| Example | <h1> | <h1>Welcome</h1> |
| Analogy | Bread की एक slice | पूरा sandwich |
Empty (Self-Closing / Void) Elements — closing tag नहीं
कुछ elements में sandwich करने को content ही नहीं, इसलिए उनका closing tag होता ही नहीं:
<br> line break
<hr> horizontal line
<img src="a.jpg" alt="..."> image
<input type="text"> form field
<meta charset="UTF-8"> page info
<link rel="stylesheet"> CSS attach
Slash के साथ <br/> लिखना भी valid है (पुरानी XHTML आदत) — HTML5 में <br> और <br/> दोनों चलते हैं. पर <br></br> गलत है — void element कभी closing tag नहीं लेता.
Case Sensitivity — हमेशा lowercase
<P>चलता है पर amateur दिखता है</P>
<p>Professional standard</p>
HTML tags case-sensitive नहीं हैं — <P> और <p> दोनों render होते हैं. पर universal convention (और XHTML/JSX की ज़रूरत) है हर जगह lowercase. आदत अभी बनाइए; आगे मिलने वाले frameworks इसकी मांग करेंगे.
Exam Corner
Q: Closing tag भूल जाएं तो क्या होता है? Browser अंदाज़ा लगाता है कि कहां खत्म होना चाहिए — कभी सही, कभी बाकी पूरा page उस element में निगल जाता है. Page के नीचे तक भागता bold text = ऊपर कहीं बिना बंद हुआ <b>.
Q: क्या <br></br> valid है? नहीं — void elements के closing tags होते ही नहीं. सिर्फ <br> या <br/>.
💻 Live Code Editor
इस पेज का code यहाँ तैयार है — बदलिए और तुरंत नतीजा देखिए. कुछ install किए बिना.console.log देखने के लिए F12 दबाइए.