HTML
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title</title>
<!-- External CSS and JavaScript files can be linked here -->
</head>
<body>
<!-- Content of the webpage goes here -->
<h1>Welcome to My Website</h1>
<p>This is a basic HTML structure.</p>
</body>
</html>
1. <!DOCTYPE html>: Declares the document type and version of HTML (HTML5 in
this case).
2. <html>: The root element of the HTML document that contains all the content.
o lang="en": Specifies the language of the document (English in this case).
3. <head>: Contains meta-information about the document, such as:
o <meta charset="UTF-8">: Defines the character encoding for the document
(UTF-8 is a common encoding that supports most characters).
o <meta name="viewport" content="width=device-width, initial-
scale=1.0">: Ensures the page is responsive and scales well on different
devices.
o <title>: Specifies the title of the webpage, which appears in the browser tab.
4. <body>: Contains the visible content of the webpage. Here you can include text,
images, links, forms, and other HTML elements.
This is the bare-bones template for any HTML document. You can expand it by adding more
elements like headings (<h2>, <h3>), paragraphs (<p>), images (<img>), links (<a>), and
more, depending on the needs of your webpage.
2. In HTML, lists and tables are commonly used elements to display structured data. Here's
how you can create both:
1. Lists in HTML
There are three types of lists in HTML: unordered lists, ordered lists, and definition lists.
Unordered List (<ul>)
An unordered list is used to display a list of items without a specific order. It uses bullet
points by default.
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
An ordered list is used when the order of the items matters (e.g., steps in a process). It is
numbered by default.
<ol>
<li>Step 1: Open the browser.</li>
<li>Step 2: Go to the website.</li>
<li>Step 3: Click the "Start" button.</li>
</ol>
A definition list is used for terms and their descriptions, typically seen in a glossary.
<dl>
<dt>HTML</dt>
<dd>A markup language used for creating web pages.</dd>
<dt>CSS</dt>
<dd>A language used to style HTML elements.</dd>
</dl>
2. Tables in HTML
Tables are used to display data in a structured, grid-like format. They consist of rows and
columns.
Explanation:
<thead>: This section contains the table headers (like column titles).
<tbody>: Contains the table body, which holds the actual data.
<th>: Defines a header cell (typically bolded and centered).
<td>: Defines a standard data cell.
If you want to add borders around your table cells, you can use the border attribute in the
<table> tag (or use CSS for more control):
<table border="1">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>15</td>
<td>A</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>16</td>
<td>B</td>
</tr>
</tbody>
</table>
Summary:
Unordered List (<ul>): Displays a list without any specific order (bullets).
Ordered List (<ol>): Displays a list with a specific order (numbered).
Definition List (<dl>): Displays terms and their definitions.
Table (<table>): Displays data in rows and columns, with optional header and footer
sections.
You can style these elements with CSS to enhance their appearance, and use JavaScript to
interact with the content dynamically.
In HTML, links and images are essential elements for navigation and displaying media
content on a webpage. Below are the basic ways to use them:
The <a> tag is used to create hyperlinks, allowing users to navigate to other pages or
resources.
Basic Link
<a href="https://www.example.com">Click here to visit Example</a>
To open the link in a new browser tab or window, use the target="_blank" attribute:
You can link to a specific part of the same page using an anchor link.
The <img> tag is used to embed images into a webpage. It does not have a closing tag.
Basic Image
<img src="image.jpg" alt="Description of the image">
You can set the width and height of an image using the width and height attributes, or
through CSS.
You can use an image as a clickable link by wrapping the <img> tag inside an <a> tag.
<a href="https://www.example.com">
<img src="image.jpg" alt="Click to visit Example">
</a>
If the image is hosted externally, use the full URL in the src attribute:
loading="lazy": Enables lazy loading for images, meaning the image will load only
when it is about to appear on the screen (useful for performance optimization).
<img src="image.jpg" alt="Lazy loaded image" loading="lazy">
Summary:
Links (<a>): Use the href attribute to define the destination URL. You can also use
target="_blank" to open links in a new tab or use anchor links (#id) to link within the
same page.
Images (<img>): Use the src attribute to define the image source and the alt attribute for
accessibility. You can control the image size with width and height attributes or CSS.
These are basic examples, but links and images are powerful tools that can be enhanced with
CSS and JavaScript for interactive and responsive web designs.