What are the basic rules of HTML ?
HTML (Hypertext Markup Language) is a markup language used to structure content on the web. Here are some basic rules to keep in mind when working with HTML:
1.Document Structure:
- An HTML document is structured using tags to define elements.
- It starts with a
<!DOCTYPE html>
declaration to specify the HTML version and is followed by the<html>
element, which contains the entire document. - The document is divided into two main sections:
<head>
(metadata) and<body>
(content).
2.Tags and Elements:
- HTML uses tags to define elements. Tags are enclosed in angle brackets, e.g.,
<tagname>
. - Elements are made up of an opening tag, content, and a closing tag, e.g.,
<p>Paragraph content</p>
.
3.Nesting:
HTML elements can be nested inside other elements. Proper nesting is crucial for maintaining document structure.
Example:
<div>
<p>This is a nested paragraph.</p>
</div>
4.Attributes:
- HTML elements can have attributes that provide additional information about the element.
- Attributes are added to the opening tag and are usually in name-value pairs.
- Example:
<a href="https://www.example.com">Visit Example.com</a>
5.Document Metadata:
The <head>
section contains metadata such as the document title, character encoding, viewport settings, and links to external resources (stylesheets, scripts).
Example:
<head>
<title>My Webpage</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
</head
6. Text Content:
- Text content is placed within various elements such as
<p>
,<h1>
to<h6>
,<span>
, etc. - Paragraphs are often defined using the
<p>
element, and headings with<h1>
to<h6>
.
7. Lists:
- HTML supports ordered lists (
<ol>
), unordered lists (<ul>
), and definition lists (<dl>
). - List items are defined using the
<li>
element. - Example:
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
8. Images:
- Images are added using the
<img>
element, and thesrc
attribute is used to specify the image file. - Example:
<img src="image.jpg" alt="Description of the image">
9. Links:
- Hyperlinks are created using the
<a>
element, and thehref
attribute is used to specify the destination URL. - Example:
<a href="https://www.example.com">Visit Example.com</a>
Comments:
- Comments in HTML are written using the
<!-- Comment here -->
syntax. - Comments are not displayed on the webpage and are useful for adding notes to the code.
These basic rules provide a foundation for creating HTML documents. It’s important to follow these conventions to ensure proper rendering of content in web browsers and maintain a well-structured and readable codebase.
Pingback: what is python language ? python tutorial - aarudeep