← Back to HTML Course | Chapter 3: Page Structure | Lesson 7 of 12

HTML Head

सोचिए आपका webpage एक actor है जो stage पर जाने का इंतज़ार कर रहा है। body वह physical actor है जिसे सब देखते हैं, लेकिन head backstage director, makeup artist, और script coordinator — सब एक साथ है। HTML head section उस code का container है जो आपके webpage visitors को कभी दिखाई नहीं देता। यह backend instructions, setups, page metadata, search engine optimizations, और stylesheet linkages को संभालता है। बिना head section के, browsers को यह पता नहीं चलेगा कि आप किस language में लिख रहे हैं, Google आपके page context को index नहीं कर पाएगा, और आपकी खूबसूरत styles कभी load नहीं होंगी।
Syntax
markup
<head>
  <title>Title</title>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="styles.css">
  <script src="script.js"></script>
</head>

head Container

head element शुरुआती html tag और दिखने वाले body tag के बीच में होता है। इसमें metadata, stylesheet links, page titles, और आपके document को configure करने के लिए ज़रूरी अन्य administrative scripts होते हैं।

Note: head container कोई दिखने वाला visual layout element render नहीं करता; दिखने वाले designs के लिए body container इस्तेमाल करें।
Warning: head section के अंदर h1 या p जैसे visible text tags कभी न रखें, क्योंकि यह HTML parsing standards का उल्लंघन करता है।

उदाहरण: The head Container

markup
<html>
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p>Visible content</p>
  </body>
</html>

Document Character Sets को Define करना

Webpages हजारों unique letters, math signs, और emojis दिखाते हैं। meta charset tag browser को बताता है कि इन symbols को बिना टूटे-फूटे, गड़बड़ कोड दिखाए सुरक्षित रूप से कैसे पढ़ना और render करना है।

Note:
  • global languages और emojis को natively support करने के लिए हमेशा अपने document character set के रूप में UTF-8 तय करें।
  • Accepted attributes:
  • charset — utf-8 (Living Standard में इकलौता अनुमत value)
  • http-equiv="Content-Type" content="text/html; charset=utf-8" — पुराना equivalent
Warning: character set meta tag को अपने head section की पहली कुछ lines के अंदर ही रखा जाना चाहिए, ताकि browsers इसे जल्दी पढ़ सकें।

उदाहरण: Defining Document Character Sets

markup
<head>
  <meta charset="UTF-8">
</head>

Search Engine Metadata को Configure करना

Search engines मेटा description tags का इस्तेमाल आपकी clickable blue headline के नीचे summary snippets दिखाने के लिए करते हैं। एक descriptive description click-through rates बढ़ाता है।

Note:
  • Google द्वारा truncate होने से बचाने के लिए अपने meta descriptions को 150 से 160 characters के बीच रखें।
  • Accepted attributes:
  • name — description | keywords | robots | author | viewport | theme-color
  • content — उस name की value
  • robots content — index | noindex | follow | nofollow
Warning: भ्रामक descriptions न लिखें, क्योंकि search engines खराब user experience के लिए आपकी site का quality score घटा देंगे।

उदाहरण: Configuring Search Engine Metadata

markup
<head>
  <meta name="description" content="Learn HTML basics with simple examples.">
</head>

बाहरी Stylesheets को Connect करना

link element आपके webpage को बाहरी CSS stylesheets से जोड़ने के लिए head section के अंदर रहता है। यह browser को बताता है कि आपके layout theme और design files कहाँ मौजूद हैं ताकि वह page को सही तरीके से render कर सके।

Note:
  • हमेशा rel="stylesheet" attribute इस्तेमाल करें, ताकि browser को पता चले कि linked resource में design rules हैं।
  • Accepted attributes:
  • rel — stylesheet
  • href — CSS फ़ाइल का URL
  • media — media query, जैसे print | (max-width: 600px)
  • integrity / crossorigin — Subresource Integrity
Warning: अगर stylesheet link टूटा हो या head tag के बाहर रखा हो, तो webpage unstyled text के रूप में render होगा।

उदाहरण: Connecting External Stylesheets

markup
<head>
  <link rel="stylesheet" href="styles.css">
</head>

Head में Scripts Inject करना

head section आमतौर पर उन JavaScript files को load करने के लिए इस्तेमाल होता है जिन्हें जल्दी parse होना चाहिए, जैसे page tracking, layout handlers, या font loaders।

Note:
  • अपने head script tags पर defer attribute इस्तेमाल करें, ताकि कोड चलने से पहले आपका HTML structure लोड होना पूरा कर ले।
  • Accepted attributes:
  • src — बाहरी script का URL
  • defer — boolean
  • async — boolean
  • type — module | text/javascript
Warning: head में बिना defer के heavy script files load करने से आपके page load times में देरी हो सकती है और blank white screens दिख सकती हैं।

उदाहरण: Injecting Scripts into the Head

markup
<head>
  <script src="tracker.js" defer></script>
</head>

base Element

base element page पर हर relative link और form के लिए एक जगह पर default URL और default target सेट कर देता है।

हर एक link पर पूरा domain लिखने के बजाय, आप इसे head में एक बार declare करते हैं और हर relative href अपने-आप उसके सापेक्ष resolve हो जाता है।

Note:
  • एक page में सिर्फ एक ही base element हो सकता है, और यह link या img tags जैसे URL इस्तेमाल करने वाले किसी भी अन्य element से पहले आना चाहिए।
  • Accepted attributes:
  • href — relative URLs के लिए base URL
  • target — _self | _blank | _parent | _top
  • सिर्फ एक base element, head में रखा गया
Warning: base tag जोड़ने से page पर मौजूद हर relative link का मतलब एक साथ बदल जाता है, जिससे अगर आप भूल जाएं कि यह वहां है, तो confusing bugs हो सकते हैं।

उदाहरण: The base Element

markup
<head>
  <base href="https://example.com/" target="_blank">
</head>

Canonical Links

rel=canonical link search engines को बताता है कि जब एक जैसे content को कई अलग-अलग URLs के जरिए एक्सेस किया जा सकता हो (जैसे tracking parameters के साथ और बिना), तो कौन-सा एक URL page का official version है।

यह search engines को duplicate versions को अलग pages मानने और आपके ranking signals को उनके बीच बांटने से रोकता है।

Note:
  • हर page पर एक self-referencing canonical tag जोड़ें, भले ही आपको लगे कि कोई duplicate नहीं है — यह accidental duplicate content के खिलाफ एक सस्ता safety net है।
  • Accepted attributes:
  • rel — canonical
  • href — page के preferred version का absolute URL
Warning: canonical tag को गलत URL पर point करने से गलती से search engines को उस page को index करना बंद करने का संकेत मिल सकता है, जिसे आप वाकई लोगों तक पहुंचाना चाहते थे।

उदाहरण: Canonical Links

markup
<head>
  <link rel="canonical" href="https://example.com/page">
</head>

Resource Hints (preload, prefetch, preconnect)

Resource hints आपको browser को ज़रूरी resources के बारे में पहले से बता देने देते हैं, इससे पहले कि वह सामान्य रूप से उन्हें खोजे। preload वर्तमान page के लिए तुरंत ज़रूरी चीज़ लाता है, prefetch उस चीज़ को लाता है जो user के अगले page पर जाने पर काम आ सकती है, और preconnect किसी दूसरे domain से पहले ही connection खोल देता है ताकि बाद के requests तेज़ हो जाएं।

Note:
  • अपने सबसे ज़रूरी above-the-fold font या hero image के लिए preload इस्तेमाल करें, क्योंकि वे अक्सर देर से load होते हैं और visible layout shifts कर देते हैं।
  • Accepted attributes:
  • rel — preload | prefetch | preconnect | dns-prefetch | modulepreload
  • href — resource का URL
  • as — script | style | font | image | fetch | audio | video | track
  • crossorigin — anonymous | use-credentials (fonts के लिए ज़रूरी)
  • type — MIME type
Warning: एक साथ बहुत सारे resources को preload करना वास्तव में page को धीमा कर सकता है, क्योंकि यह bandwidth के लिए दूसरे critical requests से compete करता है।

उदाहरण: Resource Hints (preload, prefetch, preconnect)

markup
<head>
  <link rel="preload" href="hero.jpg" as="image">
  <link rel="preconnect" href="https://fonts.example.com">
</head>

noscript Element

noscript element में वह content होता है जो सिर्फ तब दिखता है जब browser में JavaScript disabled हो या वह इसे support न करता हो।

इससे आप users को silently टूटा हुआ page दिखाने के बजाय यह बताने वाला helpful message दिखा सकते हैं कि कुछ features के लिए JavaScript ज़रूरी है।

Note: एक खाली जगह छोड़ने के बजाय, noscript का इस्तेमाल यह बताने के लिए करें कि क्या missing है, जैसे 'calculator tool इस्तेमाल करने के लिए कृपया JavaScript enable करें'।
Warning: noscript के अंदर मौजूद content उन users को कभी नहीं दिखता जिनके पास JavaScript enabled है, जो कि ज्यादातर visitors होते हैं — वहां essential content न रखें।

उदाहरण: The noscript Element

markup
<noscript>
  Please enable JavaScript to use the calculator tool.
</noscript>
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 12 topics to unlock

0/12 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.