← Back to HTML Course | Chapter 1: Introduction & Basics | Lesson 4 of 11

HTML Elements

एक HTML element पूरा package है: opening tag, अंदर का content, और closing tag। इसे एक sandwich की तरह सोचें। tags bread की slices हैं, और अंदर का text या image filling है। एक webpage पर सब कुछ इन छोटे content sandwiches से बना होता है जो एक-दूसरे के अंदर nested होते हैं।
Syntax
markup
<tagname attribute="value">content</tagname>

<tagname attribute="value" />

एक Element की संरचना

ज़्यादातर HTML elements को एक opening tag, अंदर के content, और forward slash वाले closing tag की ज़रूरत होती है। closing tag भूल जाना beginners की सबसे आम गलतियों में से एक है और इसके बाद आने वाले पूरे layout को तोड़ सकता है।

Note: layout टूटने से बचाने के लिए अपने tags को हमेशा उसी क्रम के उल्टे क्रम में close करें जिसमें आपने उन्हें खोला था।
Warning: closing tag भूल जाने से बाद के elements गलत तरीके से merge हो सकते हैं या unexpected styling दिखा सकते हैं।

उदाहरण: The Structure of an Element

markup
<p>This is the inner content.</p>

Nested Elements

HTML आपको elements को दूसरे elements के अंदर रखने देता है। इसे nesting कहा जाता है, और इसी तरह हम complex web layouts बनाते हैं।

सही nesting मायने रखती है: tags को उसी क्रम के उल्टे क्रम में close होना चाहिए जिसमें वे खुले थे, वरना ब्राउज़र आपके markup को अप्रत्याशित तरीके से auto-correct करने की कोशिश करेगा।

Note: यह आसानी से देखने के लिए कि कौन से elements किन-किन के अंदर nested हैं, अपने code editor में indentation का उपयोग करें।
Warning: सही nesting order के बिना overlapping tags browser parsing errors पैदा कर सकते हैं।

उदाहरण: Nested Elements

markup
<div>
  <p>Nested inside a div.</p>
</div>

Empty Elements

कुछ elements में कोई content या closing tags नहीं होते। इन्हें empty या self-closing elements कहा जाता है, और इनका उपयोग images, line breaks, या metadata जैसी चीज़ें insert करने के लिए किया जाता है।

आम उदाहरणों में img, br, hr, और input शामिल हैं -- इनके लिए closing tag लिखना, element के आधार पर या तो ignore हो जाता है या invalid होता है।

Note: modern HTML5 में, आपको empty tags में trailing slash जोड़ने की ज़रूरत नहीं है।
Warning: br या img जैसे empty elements के opening और closing tag के बीच content जोड़ने की कोशिश न करें।

उदाहरण: Empty Elements

markup
<img src="photo.jpg" alt="Photo">
<br>
<hr>
<input type="text">

Block बनाम Inline Elements

div और p जैसे block-level elements हमेशा नई line पर शुरू होते हैं और उपलब्ध पूरी width लेते हैं, जबकि span और a जैसे inline elements बिना line break किए आसपास के text के flow के अंदर बैठते हैं।

उदाहरण: Block vs Inline Elements

markup
<div>
  <p>Block elements start on a new line.</p>
  <span>Inline</span> <a href="#">elements</a> stay in the flow.
</div>

Void Elements Reference

img, br, और input के अलावा, HTML void elements की एक निश्चित list define करता है जिसमें hr, meta, link, और source शामिल हैं, जो specification के अनुसार कभी भी content या closing tag नहीं रखते।

उदाहरण: Void Elements Reference

markup
<hr>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<source src="video.mp4" type="video/mp4">
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
🔒

Chapter Quiz — Complete all 11 topics to unlock

0/11 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.