HTML स्टाइल गाइड
In this page:
lowercase का महत्व
हालांकि HTML case-insensitive है, tags और attributes को lowercase में लिखना industry standard है। इसे W3C द्वारा recommend किया जाता है और XHTML जैसे strict formats में यह जरूरी भी है।
उदाहरण: The Importance of lowercase
<p>Correct: lowercase tag names</p>
<P>Incorrect: uppercase tag names</P>
Attribute Quotes को Standardize करना
HTML आपको attribute values के चारों ओर quotes छोड़ने की अनुमति देता है, अगर उनमें spaces न हों। हालांकि, quotes छोड़ना एक बुरी आदत है जो values में spaces या special characters होने पर layout-breaking errors पैदा कर सकती है।
उदाहरण: Standardizing Attribute Quotes
<!-- Correct: quotes protect values with spaces -->
<img src="my photo.jpg" alt="My photo">
<!-- Bad: omitting quotes breaks multi-word values -->
<img src=my photo.jpg alt=My photo>
Consistent Indentation और Nesting
Indentation इस बात पर असर नहीं डालता कि browser आपके page को कैसे render करता है, लेकिन readability के लिए यह बेहद जरूरी है। nested child elements को 2 या 4 spaces से indent करने से आपका page structure एक नज़र में पढ़ना आसान हो जाता है।
उदाहरण: Consistent Indentation and Nesting
<div>
<p>Indented by 2 spaces</p>
</div>
Self-Closing Elements को Close करना
आधुनिक HTML5 में, self-closing elements (जैसे img या br) में trailing slash जोड़ना optional है। हालांकि, एक style चुनकर पूरे प्रोजेक्ट में उसे लगातार इस्तेमाल करना साफ कोड के लिए जरूरी है।
उदाहरण: Closing Self-Closing Elements
<br>
<br />
Files और Folders का Naming
Web servers case-sensitive होते हैं। अपनी site publish करते समय टूटे हुए links से बचने के लिए, आपको अपनी files और folders को हमेशा lowercase में नाम देना चाहिए, और शब्दों को अलग करने के लिए spaces की जगह hyphens इस्तेमाल करना चाहिए।
उदाहरण: Naming Files and Folders
<link rel="stylesheet" href="css/main-styles.css">
- अपने HTML tag names के अंदर uppercase और lowercase letters मिलाना।
- spaces वाले attribute values पर double quotes छोड़ देना।
- अपने HTML files और asset folders का नाम रखते समय spaces के बजाय hyphens इस्तेमाल करना।
- professional consistency के लिए सभी HTML tag और attribute names lowercase में लिखें।
- attribute values को हमेशा double quotes में wrap करें, भले ही वे single words हों।
- अपने project को organized रखने के लिए साफ indentation और consistent naming patterns (file names के लिए hyphens) इस्तेमाल करें।
खराब formatted HTML के साथ browsers बहुत forgiving होते हैं, लेकिन अपने code को readable और maintain करने में आसान रखने के लिए style guide follow करना ज़रूरी है।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: