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

HTML Styles

plain HTML को एक नए घर की raw concrete दीवारों की तरह सोचें। यह मजबूत है, लेकिन grey और ठंडी दिखती है। इसे घर जैसा दिखाने के लिए आपको paint, carpets, और lighting चाहिए। HTML styles आपके paint brushes और design catalogs हैं। style attribute का उपयोग करके, आप colors, custom fonts, spacing, और sizes को सीधे अपने HTML elements में inject कर सकते हैं। advanced CSS में गहराई से जाने से पहले अपनी website को एक unique personality देने का यह सबसे आसान तरीका है।
Syntax
markup
<tagname style="property: value;">content</tagname>

Style Attribute Syntax

किसी भी HTML element को style करने के लिए, आप उसके opening tag के अंदर style attribute जोड़ते हैं। यह attribute semicolons से अलग किए गए property-value pairs के रूप में लिखे गए standard CSS declarations स्वीकार करता है।

Note: styling errors से बचने के लिए हर style declaration को हमेशा semicolon से खत्म करें।
Warning: सुनिश्चित करें कि आपके style property names lowercase में लिखे हों और उनके values से एक colon द्वारा अलग हों।

उदाहरण: The Style Attribute Syntax

markup
<p style="color: blue; font-size: 18px;">Styled text</p>

Text और Foreground Color नियंत्रित करना

color property किसी element के अंदर text का रंग बदलती है। आप रंगों को standard English names, hexadecimal codes (जैसे #0000ff), या RGB values का उपयोग करके define कर सकते हैं।

Hex codes असल projects में सबसे आम choice हैं क्योंकि वे shade और tone पर precise control देते हैं।

Note: Hex codes और RGB values आपको basic named options से कहीं आगे, लाखों unique रंगों तक पहुंच देते हैं।
Warning: सफेद background पर पीले text जैसे पढ़ने में मुश्किल color combinations का उपयोग करने से बचें।

उदाहरण: Controlling Text and Foreground Color

markup
<p style="color: red;">Named color</p>
<p style="color: #0000ff;">Hex color</p>
<p style="color: rgb(0,128,0);">RGB color</p>

Background Colors और Container Fills

background-color property किसी element के container का fill color set करती है। इसका उपयोग आमतौर पर highlighted alert boxes, visual cards, या custom banners बनाने के लिए किया जाता है।

readability और accessibility के लिए text color के मुकाबले पर्याप्त contrast वाला background color चुनना ज़रूरी है।

Note: आप Cookies Cursor Color Picker का उपयोग करके सुंदर hex colors पा सकते हैं।
Warning: background color जोड़ने से container का shape visually बदल जाता है, इसलिए आपको spacing के लिए padding जोड़ने की जरूरत पड़ सकती है।

उदाहरण: Background Colors and Container Fills

markup
<div style="background-color: yellow; padding: 10px;">
  Highlighted alert box
</div>

Typography और Fonts एडजस्ट करना

आप font-family property का उपयोग करके एक typeface चुनकर, और font-size property से characters का physical size control करके अपने text का दिखना पूरी तरह बदल सकते हैं।

क्योंकि हर visitor के पास हर font install नहीं होता, इसलिए अपने पसंदीदा choice के बाद sans-serif जैसी एक fallback generic family list करना best practice है।

Note: अगर आपका primary font लोड न हो, तो उसके लिए हमेशा sans-serif जैसी backup generic font family specify करें।
Warning: body text के लिए 12px जैसे absolute pixel sizes का उपयोग करने से high-resolution screens पर आपका text पढ़ने में बहुत छोटा हो सकता है।

उदाहरण: Adjusting Typography and Fonts

markup
<p style="font-family: Georgia, sans-serif; font-size: 18px;">
  Styled paragraph text
</p>

Text Alignment और Centering

By default, text अपने container के बाएं edge पर aligned होता है। text-align property आपको इस alignment को बदलने देती है, जिससे main titles को center करना या data numbers को right align करना आसान हो जाता है।

Note: Headings को center करना अच्छा दिखता है, लेकिन body text के लंबे paragraphs को center करने से बचें क्योंकि उन्हें पढ़ना मुश्किल होता है।
Warning: text-align property केवल block-level containers पर काम करती है; यह spans जैसे inline elements को align नहीं करेगी।

उदाहरण: Text Alignment and Centering

markup
<h1 style="text-align: center;">Centered Title</h1>
<p style="text-align: right;">Right-aligned number</p>
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.