HTML + CSS
HTML + CSS
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Basic Webpage</title>
</head>
<body>
<!-- Content goes here -->
</body>
</html>
<!DOCTYPE html>: Declares the document type as HTML5.
<html>: The root element that contains all the HTML content.
html
<h1>This is a Heading 1</h1>
<h2>This is a Heading 2</h2>
Paragraphs: Represented by the <p> tag.
html
<p>This is a paragraph of text.</p>
Lists: HTML provides ordered (<ol>) and unordered
(<ul>) lists.
html
<!-- Unordered list -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
html
<a href="https://www.example.com">Visit Example</a>
Images: Use the <img> tag to add images. It requires
the src attribute for the image URL and alt for a text
description.
html
<img src="image.jpg" alt="A description of the image">
4. Practical Task
</body>
</html>
Explanation:
The <div> tag in HTML is a generic container used to group together other
elements. It doesn’t add any specific styling or behavior by default but is
commonly used in conjunction with CSS to style sections of a webpage or to
structure content logically.
You can use the <div> tag to wrap content like text, images, or other
HTML elements, often to apply styles, organize layout, or group content for
interaction (e.g., with JavaScript).
<div>
<h2>This is a section of content</h2>
<p>This paragraph is inside a div container. </p>
</div>
1. HTML Tables
Tables are used to display tabular data, i.e., data organized into rows and columns.
An HTML table is defined with the <table> element and structured using:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Table Example</title>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>Occupation</th>
</tr>
<tr>
<td>Alice</td>
<td>28</td>
<td>Engineer</td>
</tr>
<tr>
<td>Bob</td>
<td>35</td>
<td>Designer</td>
</tr>
</table>
</body>
</html>
Explanation:
Sure! Let's cover tables and forms in HTML, both of which are essential for
structuring data and gathering user input, respectively.
1. HTML Tables
Tables are used to display tabular data, i.e., data organized into rows and columns.
An HTML table is defined with the <table> element and structured using:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Table Example</title>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>Occupation</th>
</tr>
<tr>
<td>Alice</td>
<td>28</td>
<td>Engineer</td>
</tr>
<tr>
<td>Bob</td>
<td>35</td>
<td>Designer</td>
</tr>
</table>
</body>
</html>
Explanation:
html
Copy code
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>Occupation</th>
</tr>
<tr>
<td colspan="3">This row spans across all three columns</td>
</tr>
<tr>
<td>Alice</td>
<td>28</td>
<td>Engineer</td>
</tr>
</table>
2. HTML Forms
Forms allow users to input data and submit it to a server for processing. Forms
contain a variety of input elements like text fields, checkboxes, radio buttons,
dropdowns, and buttons.
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Form Example</title>
</head>
<body>
</body>
</html>
Explanation:
<form action="/submit-form" method="POST">: The form's data will
be sent to the /submit-form URL via a POST request.
<input type="text">: Creates a text field.
<input type="email">: Creates a field specifically for email input.
<input type="radio">: Creates a set of radio buttons.
<input type="checkbox">: Creates a checkbox.
<input type="submit">: A submit button to send the form data.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Semantic HTML Example</title>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<article>
<h2>Article Title</h2>
<p>This is an article about web development. Semantic HTML
helps to structure the content properly.</p>
</article>
<footer>
<p>© 2024 My Website</p>
</footer>
</body>
</html>