html possible questions
html possible questions
DOCTYPE html>
<html>
<head>
<title>Student Grades</title>
</head>
<body>
<center>
<table border="1">
<caption>Student Grades</caption>
<thead>
<tr>
<th rowspan="2">Name</th>
</tr>
<tr>
<th>Subject</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sabin</td>
<td>Math</td>
<td>95</td>
</tr>
<tr>
<td rowspan="2">Sristi</td>
<td>Science</td>
<td>90</td>
</tr>
<tr>
<td>English</td>
<td>88</td>
</tr>
</tbody>
<tfoot>
<tr>
</tr>
</tfoot>
</table>
</center>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<style>
.login-box {
width: 300px;
padding: 20px;
text-align: left;
</style>
</head>
<body>
<div class="login-box">
<label for="username">Username:</label>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<button type="submit">Login</button>
</form>
</div>
</body>
</html>
What is CSS?
CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation (style) of a
document written in HTML or XML. It allows you to control the layout, colors, fonts, spacing, and other
visual aspects of a web page, separating the content from its design.
Customize the appearance of elements such as text, images, buttons, and other HTML content.
Types of CSS:
There are three main types of CSS that allow you to apply styles to HTML documents:
1. Inline CSS
2. Internal CSS
3. External CSS
1. Inline CSS
Inline CSS is used to apply styles directly to individual HTML elements. The styles are written inside the
style attribute of the element.
Example:
html
CopyEdit
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Where it’s used: Inline styles are applied directly to specific elements.
Advantages:
2. Internal CSS
Internal CSS is used when you want to apply styles to an entire page, but the styles are written in the
<style> tag within the <head> section of the HTML document.
Example:
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
text-align: center;
p{
font-size: 18px;
color: green;
</style>
</head>
<body>
<h1>This is a Heading</h1>
</body>
</html>
Where it’s used: Styles are defined in the <style> tag in the HTML document.
Advantages:
Disadvantages:
o Styles are specific to one document, requiring duplication across pages if you want the
same styles elsewhere.
3. External CSS
External CSS involves creating a separate .css file that contains all the styles for a website. This file is then
linked to the HTML document using the <link> tag in the <head> section.
Example:
HTML File:
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a Heading</h1>
</body>
</html>
css
CopyEdit
h1 {
color: blue;
text-align: center;
p{
font-size: 18px;
color: green;
Where it’s used: When styles are stored in an external .css file.
Advantages:
Disadvantages:
o Requires an additional HTTP request to load the CSS file, which can slightly impact page
load time (though this is minimal compared to the benefits).
Directly in HTML element Quick to apply, no need for Difficult to maintain for large
Inline CSS
(style attribute) external files websites
Internal Inside the <style> tag in Easy to manage for single- Not reusable across multiple
CSS <head> section page styles pages
External In a separate .css file linked Most efficient for large Requires an extra HTTP request
CSS with <link> websites, reusable for the CSS file
Inline CSS: Best for quick, temporary changes or for a small page where only a few elements
need styling.
Internal CSS: Useful for styling a single HTML page when you don’t want to create a separate CSS
file.
External CSS: Ideal for larger websites or when you want to maintain consistency and reusability
of styles across multiple pages.
ChatGPT said:
HTML forms allow users to submit data to a server, often used for collecting user input such as text,
choices, and file uploads. Forms are typically used for things like login forms, registration forms, search
bars, and more.
The <form> tag is the container for all form elements. It defines the form and determines how data will
be sent to the server.
1. action: Specifies the URL where the form data will be submitted. If not specified, the form will be
submitted to the current page.
2. method: Defines the HTTP method (GET or POST) to send the form data.
o GET: Appends the form data to the URL (not secure for sensitive data).
o POST: Sends form data in the HTTP request body (more secure and can send large
amounts of data).
3. name: Defines a name for the form. This can be used to reference the form in scripts or other
actions.
4. target: Specifies where to display the response after form submission. Values can include _blank,
_self, _parent, or _top.
6. autocomplete: Specifies whether the browser should automatically complete form fields based
on past input.
1. Text Input: <input> The <input> tag is used for various types of user inputs like text, radio
buttons, checkboxes, etc.
o Attributes of <input>:
type: Defines the type of input (e.g., text, password, radio, checkbox, etc.).
value: Defines the value sent to the server when the form is submitted.
placeholder: Specifies a short hint or example of what the input should contain.
required: Specifies that the field must be filled out before submitting the form.
2. Text Area: <textarea> The <textarea> tag is used for multi-line text input (e.g., comments or
descriptions).
o Attributes of <textarea>:
name: Defines the name of the text area for form submission.
3. Select Dropdown: <select> The <select> tag is used to create a dropdown menu where users can
choose one or more options.
o Attributes of <select>:
Example:
html
CopyEdit
<optgroup label="Europe">
<option value="Germany">Germany</option>
<option value="France">France</option>
</optgroup>
4. Radio Button: `<input type="radio"> Radio buttons allow users to choose one option from a set.
name: Groups radio buttons together so only one option can be selected.
o Attributes of <button>:
html
CopyEdit
<!DOCTYPE html>
<html>
<body>
<h2>Contact Form</h2>
<label for="country">Country:</label><br>
<option value="Nepal">Nepal</option>
<option value="USA">USA</option>
<option value="India">India</option>
</select><br><br>
<label>Gender:</label><br>
<label for="male">Male</label><br>
<label for="female">Female</label><br><br>
</form>
</body>
</html>
Summary of Common Form Tags and Attributes:
action, method, name, enctype, target, Defines the form and specifies how data
<form>
autocomplete will be sent
type, name, value, placeholder, required, Defines different types of inputs (text,
<input>
checked, maxlength, disabled radio, checkbox, etc.)
Tags:
Tags are the fundamental building blocks of HTML that define the structure and content of a
webpage.
Tags usually come in pairs: an opening tag <tag> and a closing tag </tag>.
Example: <p>This is a paragraph.</p> where <p> is the tag that represents a paragraph.
Attributes:
Attributes are placed inside the opening tag and consist of a name and a value (e.g.,
attribute="value").
Here’s a simple example of designing a CV using HTML and CSS. It includes a table for contact
information, an image for the profile picture, and some basic formatting using HTML tags like <h1>, <p>,
and <a> for links.
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="container">
<header>
<h1>Sabin Poudel</h1>
</header>
<section>
<h2>Personal Information</h2>
<table>
<tr>
<th>Full Name</th>
<td>Sabin Poudel</td>
</tr>
<tr>
<th>Birthday</th>
</tr>
<tr>
<th>Location</th>
<td>Kathmandu, Nepal</td>
</tr>
<tr>
<th>Languages</th>
</tr>
</table>
</section>
<section>
<h2>Education</h2>
<ul>
</ul>
</section>
<section>
<h2>Skills</h2>
<ul>
<li>Team Work</li>
<li>Time Management</li>
</ul>
</section>
<section>
<h2>Contact Me</h2>
</section>
</div>
</body>
</html>
css
CopyEdit
/* General Styles */
body {
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
.container {
width: 80%;
margin: 0 auto;
padding: 20px;
background-color: white;
}
header {
text-align: center;
margin-bottom: 20px;
header h1 {
font-size: 2.5em;
color: #4CAF50;
header .profile-img {
width: 150px;
height: 150px;
border-radius: 50%;
margin-top: 10px;
header p {
font-size: 1.2em;
color: #777;
h2 {
color: #4CAF50;
font-size: 1.8em;
margin-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
table th,
table td {
padding: 10px;
text-align: left;
table th {
background-color: #4CAF50;
color: white;
ul {
list-style-type: square;
padding-left: 20px;
ul li {
margin: 5px 0;
a{
color: #4CAF50;
text-decoration: none;
a:hover {
text-decoration: underline;
Header Section: Displays the name, profile picture, and contact information.
Table: Used to show personal details like birthday, location, and languages.
10. Develop a Simple Web Page to Ask User for Input (Name, Email, Phone, Gender)
Here’s a basic HTML form that asks the user for their name, email, phone number, and gender:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<label for="name">Name:</label>
<label for="phone">Phone:</label>
<label>Gender:</label><br>
<label for="male">Male</label><br>
<label for="female">Female</label><br><br>
</form>
</body>
</html>
In this code:
The form collects the user’s name, email, phone number, and gender.
The form uses the POST method to submit the data to the server.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr>
<td>First Name:</td>
</tr>
<tr>
<td>Last Name:</td>
</tr>
<tr>
<td>Password:</td>
</tr>
<tr>
<td>Gender:</td>
<td>
</td>
</tr>
<tr>
<td>Select Programme:</td>
<td>
<option value="">Select</option>
<option value="BSC">BSC</option>
<option value="BTech">BTech</option>
</select>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>