Part 2: Mastering HTML Building Blocks
Senior Full-Stack Developer
HTML tags are the basic building blocks of web pages
< >Basic Tag Syntax:
<tagname>Content goes here</tagname>
<tagname></tagname>Essential tags every developer should know:
Marks the beginning of an HTML element
<tagname>
Tells browser where the element starts
Can contain additional information
<p class="intro">
Marks the end of an HTML element
</tagname>
Tells browser where the element ends
Never contains attributes
</p>
<!-- Start Tag -->
<p class="intro">
<!-- Content -->
This is a paragraph of text that demonstrates how HTML tags work.
<!-- End Tag -->
</p>
<p class="intro">
This is paragraph content
</p>
All three parts together form a complete HTML element
Start on a new line and take full width
<div>
<p>
<h1>
<ul>
Flow within text and don't break lines
<span>
<a>
<strong>
<em>
Self-closing with no content
<img>
<br>
<hr>
<input>
Self-closing tags (void elements) don't have content and don't require closing tags.
<p>This is content</p>
Has opening tag, content, and closing tag
<img src="image.jpg" alt="Description">
No content, no closing tag needed
Embeds images
<img src="photo.jpg">
Line break
<br>
Horizontal rule
<hr>
Input field
<input type="text">
Metadata
<meta charset="UTF-8">
External resources
<link rel="stylesheet">
Attributes provide additional information about HTML elements and are always specified in the start tag.
<tagname attribute="value">Content</tagname>
name="value"Unique identifier for an element
id="main-header"
CSS class selector
class="btn primary"
Source file location
src="image.jpg"
Hyperlink reference
href="page.html"
Alternative text for images
alt="Description"
Inline CSS styling
style="color: red;"
<!DOCTYPE html>
<html>
<head>
<title>HTML Tags Demo</title>
</head>
<body bgcolor="#f0f8ff">
<!-- Paragraph with alignment -->
<p align="center">
This is a centered paragraph
</p>
<!-- Bold and Italic text -->
<p>
This text has <b>bold</b> and
<i>italic</i> formatting.
</p>
<!-- Multiple attributes -->
<div id="container" class="main" style="border: 1px solid blue;">
<h1 align="center">Welcome</h1>
<p>This div has ID, class, and style attributes.</p>
</div>
<!-- Self-closing tags -->
<br>
<hr width="50%" align="center">
<br>
<!-- Image with attributes -->
<img src="logodev2.jpg" alt="Company Logo" width="200" height="100">
</body>
</html>
This is a centered paragraph
This text has bold and italic formatting.
This div has ID, class, and style attributes.
<p>, <b>, <i>, <div>
align, bgcolor, id, class
<br>, <hr>, <img>
style, width, height
You've Mastered HTML Tags & Elements
Basic building blocks of web pages
Start tags and end tags
Complete building blocks
Elements without content
Extra element information
Real-world examples
Build an HTML file with:
<h1><b> and <i>align attributebgcolor and custom stylingNext: Learn about DOCTYPE, head section, and semantic HTML