Basics of HTML
Getting Started with HTML: Essential Elements and Examples
HTML (Hypertext Markup Language) is the foundation of web development. It provides the structure and layout of web pages and helps to define elements like headings, paragraphs, links, and images. In this blog post, we’ll explore the essential HTML elements with example code to help you start building your own web pages.
1. Basic Structure of an HTML Document
Every HTML document has a standard structure, beginning with the <!DOCTYPE html>
declaration and followed by html
, head
, and body
tags. Here’s the basic structure of an HTML file:
<!DOCTYPE html>
: Declares the document type as HTML5.<html>
: The root element that wraps all HTML content.<head>
: Contains meta-information, like the page title, which is shown in the browser tab.<title>
: Sets the title of the page.<body>
: Contains all the content displayed on the web page.
2. Headings (<h1>
to <h6>
)
Headings are essential for organizing content. HTML provides six heading tags, from <h1>
(most important) to <h6>
(least important).
3. Paragraphs (<p>
)
The <p>
tag is used for adding paragraphs.
<p>This is a paragraph. HTML paragraphs are automatically separated by a small margin.</p>
4. Links (<a>
)
Links are created using the <a>
tag, which has an href
attribute to define the URL.
<a href="https://www.example.com">Visit Example</a>
5. Images (<img>
)
The <img>
tag displays images on a webpage. The src
attribute specifies the image source, and the alt
attribute provides alternate text.
<img src="image.jpg" alt="A descriptive text for the image">
6. Lists
HTML supports both ordered (<ol>
) and unordered (<ul>
) lists. Each list item is wrapped in <li>
tags.
7. Divisions (<div>
) and Spans (<span>
)
<div>
: A block-level container, often used for layout purposes.
<span>
: An inline container for text or small groups of elements, often used to style specific portions of text.8. Tables (<table>
)
Tables are used to display data in rows and columns.
<table>
: Defines the table.<tr>
: Defines a row.<th>
: Defines a header cell (bold and centered).<td>
: Defines a standard cell.9. Forms (<form>
)
Forms allow users to submit data. Here’s an example with text and submit inputs.
10. Comments
Comments in HTML are written within <!-- -->
. They’re not displayed in the browser but help document the code.
Comments
Post a Comment