HTML Basic
Headings, Paragraphs, Links, Images, Buttons, Attributes ਅਤੇ ਪੂਰੇ HTML Pages ਦੀਆਂ ਵਿਹਾਰਕ ਉਦਾਹਰਨਾਂ ਰਾਹੀਂ ਬੁਨਿਆਦੀ HTML ਸਿੱਖੋ।
ਪਿਛਲੇ ਅਧਿਆਇ ਵਿੱਚ, ਤੁਸੀਂ Code Editor ਦੀ ਵਰਤੋਂ ਕਰਕੇ HTML File ਬਣਾਉਣਾ, Save ਕਰਨਾ ਅਤੇ Open ਕਰਨਾ ਸਿੱਖਿਆ ਸੀ।
ਹੁਣ ਆਓ ਕੁਝ ਬੁਨਿਆਦੀ HTML Examples ਵੇਖੀਏ!
Code ਲਿਖਣ ਅਤੇ ਇਸਦੇ Output ਨੂੰ ਦੇਖਣ ਨਾਲ HTML ਨੂੰ ਸਮਝਣਾ ਹੋਰ ਵੀ ਆਸਾਨ ਹੋ ਜਾਂਦਾ ਹੈ।
ਇਸ ਅਧਿਆਇ ਵਿੱਚ, ਤੁਸੀਂ ਸਿੱਖੋਗੇ ਕਿ ਇੱਕ ਬੁਨਿਆਦੀ HTML Document ਕਿਵੇਂ ਬਣਾਇਆ ਜਾਂਦਾ ਹੈ ਅਤੇ Headings, Paragraphs, Links, Images ਅਤੇ Buttons ਵਰਗੇ ਆਮ Elements ਕਿਵੇਂ ਜੋੜੇ ਜਾਂਦੇ ਹਨ।
ਤੁਸੀਂ HTML Source Code ਦੇਖਣਾ ਅਤੇ HTML Tags ਤੇ Attributes ਵਿਚਕਾਰ ਅੰਤਰ ਸਮਝਣਾ ਵੀ ਸਿੱਖੋਗੇ।
A Basic HTML Document
ਹਰ HTML Page ਇੱਕ ਬੁਨਿਆਦੀ Document Structure ਨਾਲ ਸ਼ੁਰੂ ਹੁੰਦਾ ਹੈ।
Example:
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to W3PrimeCode</h1>
<p>This is my first HTML page.</p>
</body>
</html>Example Explained
| Code | Description |
|---|---|
| \<!DOCTYPE html> | ਘੋਸ਼ਣਾ ਕਰਦਾ ਹੈ ਕਿ Document HTML5 ਦੀ ਵਰਤੋਂ ਕਰਦਾ ਹੈ। |
| \<html> | HTML Document ਦਾ Root Element ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ। |
| \<head> | Document Metadata ਰੱਖਦਾ ਹੈ। |
| \<title> | Browser Tab ਦਾ Title ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ। |
| \<body> | ਮੁੱਖ ਦਿਖਾਈ ਦੇਣ ਵਾਲਾ Page Content ਰੱਖਦਾ ਹੈ। |
| \<h1> | ਸਭ ਤੋਂ ਉੱਚੇ ਪੱਧਰ ਦੀ Heading ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ। |
| \<p> | ਇੱਕ Paragraph ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ। |
Important: <body> ਦੇ ਅੰਦਰ ਮੌਜੂਦ Content ਹੀ ਆਮ ਤੌਰ 'ਤੇ users ਨੂੰ Web Page 'ਤੇ ਦਿਖਾਈ ਦਿੰਦਾ ਹੈ।
HTML Headings
HTML Headings ਦੀ ਵਰਤੋਂ Web Page 'ਤੇ Titles ਅਤੇ Section Headings ਪਰਿਭਾਸ਼ਿਤ ਕਰਨ ਲਈ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
HTML ਵਿੱਚ <h1> ਤੋਂ <h6> ਤੱਕ Headings ਦੇ ਛੇ ਪੱਧਰ ਹੁੰਦੇ ਹਨ।
<h1>ਸਭ ਤੋਂ ਉੱਚੇ ਪੱਧਰ ਦੀ Heading ਦਰਸਾਉਂਦਾ ਹੈ।<h6>ਸਭ ਤੋਂ ਹੇਠਲੇ ਪੱਧਰ ਦੀ Heading ਦਰਸਾਉਂਦਾ ਹੈ।
Example:
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>ਅਸਲ Heading Sizes Browser ਦੀਆਂ Default Styles ਜਾਂ Page 'ਤੇ ਲਾਗੂ ਕੀਤੇ CSS 'ਤੇ ਨਿਰਭਰ ਕਰਦੇ ਹਨ।
Remember: Heading Levels ਸਿਰਫ਼ Text ਨੂੰ ਵੱਡਾ ਜਾਂ ਛੋਟਾ ਕਰਨ ਲਈ ਨਾ ਚੁਣੋ। ਆਪਣੇ Content ਦੇ Structure ਅਤੇ Hierarchy ਦੇ ਅਨੁਸਾਰ Heading Levels ਚੁਣੋ।
HTML Paragraphs
<p> Element ਇੱਕ Paragraph ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ।
Paragraph ਦੀ ਵਰਤੋਂ ਆਮ ਤੌਰ 'ਤੇ Text Blocks ਦਿਖਾਉਣ ਲਈ ਕੀਤੀ ਜਾਂਦੀ ਹੈ, ਜਿਵੇਂ ਕਿ Descriptions, Explanations ਜਾਂ Introductions।
Example:
<p>This is my first paragraph.</p>
<p>This is my second paragraph.</p>Browsers ਆਮ ਤੌਰ 'ਤੇ Paragraphs ਨੂੰ Default Spacing ਦੇ ਨਾਲ ਵੱਖਰੇ Blocks ਵਜੋਂ ਦਿਖਾਉਂਦੇ ਹਨ।
ਤੁਸੀਂ ਲੋੜ ਅਨੁਸਾਰ ਜਿੰਨੇ ਮਰਜ਼ੀ Paragraphs ਬਣਾ ਸਕਦੇ ਹੋ।
HTML Links
HTML Links users ਨੂੰ ਇੱਕ Web Page ਤੋਂ ਦੂਜੇ Web Page 'ਤੇ ਜਾਣ ਦੀ ਸਹੂਲਤ ਦਿੰਦੇ ਹਨ।
Links ਬਣਾਉਣ ਲਈ <a> Element ਦੀ ਵਰਤੋਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
Basic Syntax:
<a href="URL">Link Text</a>Example:
<a href="https://www.example.com">
Visit Example Website
</a>Example Explained
<a>ਇੱਕ Hyperlink ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ।hrefਇੱਕ Attribute ਹੈ ਜੋ Link ਦੀ Destination ਦੱਸਦਾ ਹੈ।Visit Example Websiteਕਲਿੱਕ ਕਰਨ ਯੋਗ Link Text ਹੈ।</a>Element ਨੂੰ ਬੰਦ ਕਰਦਾ ਹੈ।
Important: ਹਮੇਸ਼ਾ ਅਰਥਪੂਰਨ Link Text ਵਰਤੋ ਤਾਂ ਜੋ users ਸਮਝ ਸਕਣ ਕਿ Link ਉਨ੍ਹਾਂ ਨੂੰ ਕਿੱਥੇ ਲੈ ਕੇ ਜਾਵੇਗਾ।
HTML Images
HTML Page ਵਿੱਚ Image ਸ਼ਾਮਲ ਕਰਨ ਲਈ <img> Element ਦੀ ਵਰਤੋਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
ਕਈ ਹੋਰ HTML Elements ਤੋਂ ਵੱਖਰਾ, <img> ਇੱਕ Void Element ਹੈ ਅਤੇ ਇਸਨੂੰ End Tag ਦੀ ਲੋੜ ਨਹੀਂ ਹੁੰਦੀ।
Basic Syntax:
<img src="image.jpg" alt="Image description">Example:
<img
src="https://www.w3.org/Icons/w3c_home"
alt="W3C Logo"
width="100"
>Expected Output:
ਜੇ ਦਿੱਤਾ ਗਿਆ Image Resource ਉਪਲਬਧ ਹੈ, ਤਾਂ Browser Image ਦਿਖਾਏਗਾ।
Example Explained
| Attribute | Description |
|---|---|
| src | Image ਦੀ Location ਦੱਸਦਾ ਹੈ। |
| alt | Image ਦਾ ਵਰਣਨ ਕਰਨ ਵਾਲਾ Alternative Text ਦਿੰਦਾ ਹੈ। |
| width | ਦਿਖਾਈ ਜਾਣ ਵਾਲੀ Image ਦੀ Width ਦੱਸਦਾ ਹੈ। |
Why is alt important?
ਜੇ Image ਦਿਖਾਈ ਨਹੀਂ ਜਾ ਸਕਦੀ, ਤਾਂ alt Attribute ਉਸਦੀ ਥਾਂ Text ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ। ਇਹ Assistive Technologies ਦੀ ਵਰਤੋਂ ਕਰਨ ਵਾਲੇ users ਨੂੰ ਵੀ Image ਦਾ ਉਦੇਸ਼ ਸਮਝਣ ਵਿੱਚ ਮਦਦ ਕਰਦਾ ਹੈ।
ਜਾਣਕਾਰੀ ਦੇਣ ਵਾਲੀਆਂ Images ਲਈ ਅਰਥਪੂਰਨ Alternative Text ਲਿਖੋ।
HTML Buttons
Web Page 'ਤੇ Button ਬਣਾਉਣ ਲਈ <button> Element ਦੀ ਵਰਤੋਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
Example:
<button type="button">Click Me</button>Important: ਇਹ Button ਆਪਣੇ ਆਪ ਕੋਈ Custom Action ਨਹੀਂ ਕਰਦਾ। User ਦੇ ਇਸਨੂੰ ਕਲਿੱਕ ਕਰਨ 'ਤੇ ਕੀ ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ, ਇਹ ਪਰਿਭਾਸ਼ਿਤ ਕਰਨ ਲਈ ਤੁਸੀਂ JavaScript ਦੀ ਵਰਤੋਂ ਕਰ ਸਕਦੇ ਹੋ।
ਤੁਸੀਂ ਅਗਲੇ Tutorials ਵਿੱਚ Interactive Buttons ਬਾਰੇ ਹੋਰ ਸਿੱਖੋਗੇ।
HTML Line Breaks
Text ਦੇ ਅੰਦਰ Line Break ਜੋੜਨ ਲਈ <br> Element ਦੀ ਵਰਤੋਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
ਇਹ ਇੱਕ Void Element ਹੈ ਅਤੇ ਇਸਨੂੰ Closing Tag ਦੀ ਲੋੜ ਨਹੀਂ ਹੁੰਦੀ।
Example:
<p>
Hello World!<br>
Welcome to HTML.
</p>ਜਿੱਥੇ Content ਵਿੱਚ Line Break ਦੀ ਲੋੜ ਹੋਵੇ, ਜਿਵੇਂ ਕਿ ਕਿਸੇ Address ਜਾਂ Poem ਵਿੱਚ, ਉੱਥੇ <br> ਦੀ ਵਰਤੋਂ ਕਰੋ।
Page Sections ਵਿਚਕਾਰ ਸਿਰਫ਼ Spacing ਬਣਾਉਣ ਲਈ ਵਾਰ-ਵਾਰ <br> Elements ਦੀ ਵਰਤੋਂ ਨਾ ਕਰੋ। Layout ਅਤੇ Spacing ਲਈ CSS ਵਧੇਰੇ ਉਚਿਤ ਹੈ।
HTML Horizontal Rules
Content ਦੇ Sections ਵਿਚਕਾਰ Thematic Break ਦਰਸਾਉਣ ਲਈ <hr> Element ਦੀ ਵਰਤੋਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
Browsers ਆਮ ਤੌਰ 'ਤੇ ਇਸਨੂੰ ਇੱਕ Horizontal Line ਵਜੋਂ ਦਿਖਾਉਂਦੇ ਹਨ।
Example:
<h2>HTML Tutorial</h2>
<p>Learn HTML step by step.</p>
<hr>
<h2>CSS Tutorial</h2>
<p>Learn how to style web pages.</p>HTML Attributes
HTML Attributes, Elements ਬਾਰੇ ਵਾਧੂ ਜਾਣਕਾਰੀ ਜਾਂ Configuration ਪ੍ਰਦਾਨ ਕਰਦੇ ਹਨ।
ਇਹ ਆਮ ਤੌਰ 'ਤੇ Start Tag ਦੇ ਅੰਦਰ ਲਿਖੇ ਜਾਂਦੇ ਹਨ।
Example:
<a href="https://www.example.com">Visit Website</a>ਇੱਥੇ href ਇੱਕ Attribute ਹੈ।
Another Example:
<p title="This is a tooltip">
Move your mouse over this paragraph.
</p>title Attribute ਵਾਧੂ Advisory Information ਦੇ ਸਕਦਾ ਹੈ। ਜਦੋਂ user ਕਿਸੇ Element ਉੱਤੇ Mouse Hover ਕਰਦਾ ਹੈ, ਤਾਂ ਕਈ Desktop Browsers ਇਸਨੂੰ Tooltip ਵਜੋਂ ਦਿਖਾਉਂਦੇ ਹਨ।
General Syntax:
<tagname attribute="value">Content</tagname>ਜ਼ਿਆਦਾਤਰ Attributes ਇੱਕ Name ਅਤੇ Value ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹਨ।
ਤੁਸੀਂ ਅਗਲੇ ਅਧਿਆਇ ਵਿੱਚ HTML Attributes ਬਾਰੇ ਹੋਰ ਵਿਸਥਾਰ ਨਾਲ ਸਿੱਖੋਗੇ।
How to View HTML Source Code
ਤੁਸੀਂ ਆਪਣੇ Browser ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਕਈ Web Pages ਦਾ HTML Source Code ਦੇਖ ਸਕਦੇ ਹੋ।
Method 1: View Page Source
ਜ਼ਿਆਦਾਤਰ Desktop Browsers ਵਿੱਚ:
- ਇੱਕ Web Page Open ਕਰੋ।
- ਖਾਲੀ ਥਾਂ 'ਤੇ Right-click ਕਰੋ।
- View Page Source ਚੁਣੋ।
ਤੁਸੀਂ ਆਮ ਤੌਰ 'ਤੇ ਇਹ Keyboard Shortcuts ਵੀ ਵਰਤ ਸਕਦੇ ਹੋ:
- Windows/Linux:
Ctrl + U - macOS: ਸਮਰਥਿਤ Browsers ਵਿੱਚ
Option + Command + U
ਇਹ ਉਸ Page ਲਈ ਪ੍ਰਾਪਤ ਹੋਇਆ HTML Source ਦਿਖਾਉਂਦਾ ਹੈ।
Method 2: Inspect Element
ਆਧੁਨਿਕ Desktop Browsers ਵਿੱਚ Developer Tools ਸ਼ਾਮਲ ਹੁੰਦੇ ਹਨ।
ਕਿਸੇ ਖਾਸ Element ਨੂੰ Inspect ਕਰਨ ਲਈ:
- ਉਸ Element 'ਤੇ Right-click ਕਰੋ।
- Inspect ਚੁਣੋ।
- Elements Panel ਵਿੱਚ HTML ਦੀ ਜਾਂਚ ਕਰੋ।
Note: View Page Source ਅਤੇ Inspect ਬਿਲਕੁਲ ਇੱਕੋ ਜਿਹੇ ਨਹੀਂ ਹਨ। View Page Source ਆਮ ਤੌਰ 'ਤੇ Original HTML Response ਦਿਖਾਉਂਦਾ ਹੈ, ਜਦਕਿ Inspect ਮੌਜੂਦਾ DOM ਦਿਖਾਉਂਦਾ ਹੈ, ਜਿਸਨੂੰ JavaScript ਨੇ ਬਦਲਿਆ ਹੋ ਸਕਦਾ ਹੈ।
Complete Practical Example
ਆਓ ਕਈ HTML Elements ਨੂੰ ਇੱਕ Web Page ਵਿੱਚ ਇਕੱਠੇ ਵਰਤੀਏ।
Example:
<!DOCTYPE html>
<html>
<head>
<title>My HTML Practice</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>I am learning HTML with W3PrimeCode.</p>
<h2>About HTML</h2>
<p>HTML is used to structure web content.</p>
<hr>
<h2>Useful Link</h2>
<a href="https://www.example.com">
Visit Example Website
</a>
<h2>Sample Image</h2>
<img
src="https://www.w3.org/Icons/w3c_home"
alt="W3C Logo"
width="100"
>
<h2>Button Example</h2>
<button type="button">Click Me</button>
</body>
</html>Expected Output:
Browser ਹੇਠ ਲਿਖੀਆਂ ਚੀਜ਼ਾਂ ਦਿਖਾਏਗਾ:
- ਇੱਕ Main Heading।
- ਦੋ Informational Paragraphs।
- Section Headings।
- ਇੱਕ Thematic Break।
- ਕਲਿੱਕ ਕਰਨ ਯੋਗ ਇੱਕ Link।
- ਇੱਕ Image, ਜੇ Resource ਸਫਲਤਾਪੂਰਵਕ Load ਹੁੰਦਾ ਹੈ।
- ਇੱਕ Button।
ਇਹ Example ਦਿਖਾਉਂਦਾ ਹੈ ਕਿ ਇੱਕ ਸਧਾਰਨ Web Page ਬਣਾਉਣ ਲਈ ਕਈ HTML Elements ਇਕੱਠੇ ਕਿਵੇਂ ਕੰਮ ਕਰ ਸਕਦੇ ਹਨ।
Common Beginner Mistakes
Mistake 1: Forgetting the Closing Tag
Incorrect:
<h1>Welcome
<p>Hello World</p>Correct:
<h1>Welcome</h1>
<p>Hello World</p>Mistake 2: Forgetting Quotes Around Attribute Values
HTML ਵਿੱਚ ਕੁਝ Attribute Values ਬਿਨਾਂ Quotes ਦੇ ਵੀ ਲਿਖੀਆਂ ਜਾ ਸਕਦੀਆਂ ਹਨ। ਫਿਰ ਵੀ ਹਰ ਜਗ੍ਹਾ Quotes ਦੀ ਵਰਤੋਂ ਕਰਨ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
Recommended:
<a href="https://www.example.com">Visit Website</a>Mistake 3: Missing Image Alternative Text
Not Recommended:
<img src="photo.jpg">Recommended for an informative Image:
<img src="photo.jpg" alt="A mountain landscape">Mistake 4: Using Heading Elements Only to Change Font Size
Headings, Content Hierarchy ਨੂੰ ਦਰਸਾਉਂਦੀਆਂ ਹਨ। Font Size ਅਤੇ Appearance ਨੂੰ ਨਿਯੰਤਰਿਤ ਕਰਨ ਲਈ CSS ਦੀ ਵਰਤੋਂ ਕਰੋ।
Try It Yourself
basic-examples.html ਨਾਮ ਦੀ ਇੱਕ File ਬਣਾਓ।
ਹੇਠਾਂ ਦਿੱਤਾ Starter Code ਵਰਤੋ:
<!DOCTYPE html>
<html>
<head>
<title>HTML Practice</title>
</head>
<body>
<h1>My First Website</h1>
<p>Write your introduction here.</p>
<h2>My Favorite Website</h2>
<a href="https://www.example.com">
Visit Website
</a>
</body>
</html>Your Tasks:
- Main Heading ਬਦਲੋ।
- ਦੋ ਨਵੇਂ Paragraphs ਜੋੜੋ।
<h2>ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਇੱਕ ਹੋਰ Heading ਜੋੜੋ।- ਆਪਣੀ ਪਸੰਦ ਦੀ ਕਿਸੇ Website ਲਈ Link ਬਣਾਓ।
<img>ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਇੱਕ Image ਜੋੜੋ।- ਇੱਕ Button ਜੋੜੋ।
- File Save ਕਰੋ ਅਤੇ ਆਪਣੇ Browser ਵਿੱਚ Output ਦੇਖੋ।