HTML (HyperText Markup Language) tags and elements form the backbone of a webpage’s structure and layout. HTML is used to structure content on the web, including text, images, links, and forms. Here’s a breakdown of HTML tags, elements, and some commonly used examples:
1. HTML Tags
- Tags are keywords enclosed in angle brackets (
< >
). Tags often come in pairs, an opening tag (like<tag>
) and a closing tag (like</tag>
), although some tags are self-closing. - Examples:
<p> ... </p>
: Paragraph tag<h1> ... </h1>
: Heading tag<img src="image.jpg" />
: Image tag (self-closing)
2. HTML Elements
- An HTML element consists of a start tag, content, and an end tag.
- For example, in
<p>Hello, World!</p>
,<p>
is the start tag,Hello, World!
is the content, and</p>
is the end tag. - Elements can also contain other elements, creating a nested structure.
Basic Structure of an HTML Document
Here’s the basic layout of an HTML document with commonly used tags:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<a href="https://rojgarbharat.info/">This is a link</a>
</body>
</html>
Common HTML Tags
- Document Structure Tags
<!DOCTYPE html>
: Declares the document type as HTML5.<html>
: Root element of an HTML page.<head>
: Contains meta-information like the title and links to CSS.<title>
: Sets the page title shown in the browser tab.<body>
: Contains all the content to display on the webpage.
- Text Formatting Tags
<h1> to <h6>
: Heading tags,<h1>
is the largest,<h6>
the smallest.<p>
: Paragraph tag for blocks of text.<strong>
: Bold text.<em>
: Italic text.<br>
: Line break (self-closing).<hr>
: Horizontal line (self-closing).
- Link and Image Tags
<a href="URL">
: Creates a hyperlink.<img src="URL" alt="description">
: Embeds an image (self-closing).
- List Tags
<ul>
: Unordered list.<ol>
: Ordered list.<li>
: List item (used inside<ul>
or<ol>
).
- Table Tags
<table>
: Defines a table.<tr>
: Table row.<td>
: Table cell.<th>
: Table header cell.
- Form Tags
<form>
: Form container.<input>
: Input field (self-closing).<label>
: Label for input elements.<textarea>
: Multi-line text input.<button>
: Button for submitting forms.
- Div and Span Tags
<div>
: Block-level container for grouping elements.<span>
: Inline container for styling specific parts of text.
Nesting of Tags
HTML elements can be nested within each other, allowing complex layouts. For instance:
<div>
<h2>My Blog Post</h2>
<p>This is an interesting blog post.</p>
<a href="https://rojgarbharat.info/">Read more</a>
</div>
HTML Attributes
Tags can have attributes that provide additional information:
- Common attributes include
id
,class
,src
,href
,alt
, andstyle
. - Example:
<a href="https://rojgarbharat.info/" target="_blank">Visit Example</a>
HTML Tutorial Index
HTML Elements
- HTML Tags and Elements
- Nesting HTML Elements
- Block-level vs Inline Elements
- Empty (Void) Elements
HTML Document Structure
- The
<html>
,<head>
, and<body>
Tags - Metadata:
<meta>
,<title>
- Linking External Files:
<link>
HTML Headings, Paragraphs, and Text Formatting
- Headings:
<h1>
to<h6>
- Paragraphs:
<p>
- Line Breaks and Horizontal Rules:
<br>
,<hr>
- Text Formatting Tags:
<b>
,<i>
,<strong>
,<em>
,<mark>
HTML Links (Hyperlinks)
- Creating Links: The
<a>
tag - Internal Links vs External Links
- Opening Links in New Tabs:
target="_blank"
- Linking to Email or Phone Numbers
HTML Images
- Adding Images: The
<img>
tag - Image Attributes:
src
,alt
,height
,width
- Responsive Images
- Image Formats and Optimization
HTML Lists
- Ordered Lists:
<ol>
- Unordered Lists:
<ul>
- Definition Lists:
<dl>
- Nesting Lists
HTML Tables
- Basic Table Structure:
<table>
,<tr>
,<td>
,<th>
- Table Headers and Footers
- Merging Cells:
rowspan
,colspan
- Styling Tables with CSS
HTML Forms
- The Form Tag:
<form>
- Input Types:
<input>
,text
,password
,email
,number
, etc. - Form Controls:
<textarea>
,<select>
,<option>
,<button>
- Form Validation and Attributes
- File Uploads
HTML Multimedia
- Embedding Audio:
<audio>
tag - Embedding Video:
<video>
tag - Adding Captions and Subtitles
- Embedding YouTube Videos
HTML Semantics
- Semantic Elements:
<header>
,<footer>
,<article>
,<section>
,<aside>
,<nav>
- Importance of Using Semantic Tags
HTML5 New Features
- The New Input Types:
email
,date
,url
,range
- Geolocation API
- Canvas API: Drawing Graphics
- Local Storage and Session Storage
HTML Attributes
- Global Attributes
- The
id
andclass
Attributes style
and Inline CSStitle
anddata-*
Attributes
HTML Accessibility
- Adding
alt
Text for Images - Using ARIA Attributes
- Best Practices for Accessibility
HTML Best Practices
- Writing Clean and Readable Code
- File Naming Conventions
- Organizing Project Files
- Comments and Documentation
HTML and CSS
- Linking CSS to HTML:
<link>
,<style>
- Inline, Internal, and External CSS
- Using CSS for Layout and Design
HTML and JavaScript
- Adding JavaScript:
<script>
- Event Handling with HTML
- Using JavaScript for Interactivity
Responsive Web Design
- Meta Viewport Tag
- Mobile-First Design
- Media Queries
HTML Tools and Resources
- HTML Validators
- Browser Developer Tools
- Online Code Editors and Resources