Practice Question HTML
Practice Question HTML
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</body>
</html>
Explanation:
12. the final paragraph shows how to combine many of the tags.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol>
<li>Python</li>
<li>JavaScript</li>
<li>Java</li>
<li>C++</li>
<li>C#</li>
</ol>
<ol type="A">
<li>Python</li>
<li>JavaScript</li>
<li>Java</li>
<li>C++</li>
<li>C#</li>
</ol>
<ol type="I">
<li>Python</li>
<li>JavaScript</li>
<li>Java</li>
<li>C++</li>
<li>C#</li>
</ol>
</body>
</html>
Explanation:
You can add the start attribute to the <ol> tag to change the starting
value. For example:
HTML
<ol type="A" start="5">
<li>Python</li>
<li>JavaScript</li>
<li>Java</li>
<li>C++</li>
<li>C#</li>
</ol>
HTML
<li>Python</li>
<li>JavaScript</li>
<li>Java</li>
<li>C++</li>
<li>C#</li>
</ol>
HTML
<ol start="5">
<li>Python</li>
<li>JavaScript</li>
<li>Java</li>
<li>C++</li>
<li>C#</li>
</ol>
HTML
<!DOCTYPE html>
<html>
<head>
<title>Favorite Foods</title>
</head>
<body>
<ul style="list-style-type:disc;">
<li>Pizza</li>
<li>Sushi</li>
<li>Pasta</li>
<li>Burgers</li>
<li>Ice Cream</li>
</ul>
<ul style="list-style-type:circle;">
<li>Pizza</li>
<li>Sushi</li>
<li>Pasta</li>
<li>Burgers</li>
<li>Ice Cream</li>
</ul>
<li>Pizza</li>
<li>Sushi</li>
<li>Pasta</li>
<li>Burgers</li>
<li>Ice Cream</li>
</ul>
</body>
</html>
Explanation:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Definition List</title>
</head>
<body>
<dl>
<dt>HTML</dt>
<dt>CSS</dt>
<dt>JavaScript</dt>
</dl>
</body>
</html>
Explanation:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Link Demo</title>
</head>
<body>
<h1>Link Examples</h1>
<p>
</p>
<p>
</p>
<p>
</p>
<h2 id="section1">Section 1</h2>
</body>
</html>
Explanation:
Question: Create an HTML table displaying the top 3 movies of 2024 with
the following columns: • Rank • Movie Name • IMDB Rating Expected
Output: A table with 3 rows displaying rank, name, and rating values.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border-collapse: collapse;
padding: 8px;
text-align: left;
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Rank</th>
<th>Movie Name</th>
<th>IMDB Rating</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>8.0</td>
</tr>
<tr>
<td>2</td>
<td>6.7</td>
</tr>
<tr>
<td>3</td>
<td>Godzilla x Kong: The New Empire</td>
<td>6.4</td>
</tr>
</tbody>
</table>
</body>
</html>
Explanation:
Important Note: IMDB ratings are subject to change. The movie listing is
based on information available as of the time of this response.
Question: Write an HTML code to display an image from a local folder and
another image from an online source (URL). Expected Output: Both
images should be properly displayed, with alt text in case they don't load.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Image Display</title>
</head>
<body>
<h2>Local Image</h2>
<h2>Online Image</h2>
</body>
</html>
How to test:
1. Local Image:
2. Online Image:
o Open the same images.html file. The online image should load
if you have an internet connection.
o If you change the url, make sure the new url points to a valid
image.
Question: Create an HTML page that: 1. Plays an audio file (MP3 format)
with controls. 2. Plays a video file (MP4 format) with controls and autoplay
enabled. Expected Output: An audio player and a video player should be
displayed with proper controls.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Audio Player</h2>
<audio controls>
</audio>
<h2>Video Player</h2>
</video>
</body>
</html>
To test:
4. The audio and video players should appear with controls. The video
should start playing automatically.
5. If the audio or video does not play, make sure that the files are in
the same directory as the html file, and that the file names match.
Also, make sure that the files are valid mp3 and mp4 files.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>
</p>
<p>
</p>
<h2>Explanation</h2>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</body>
</html>
Code Tags: The <code> tags are used to display the HTML tag
names, improving readability.
Question 2:
Write an HTML snippet that displays a quote block, a highlighted text, and
a code snippet
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Quote Block</h2>
<blockquote cite="https://example.com/quote-source">
</blockquote>
<h2>Highlighted Text</h2>
<h2>Code Snippet</h2>
</body>
</html>
1. <blockquote>:
2. <mark>:
3. <code>:
o For multi line code snippets the <pre> tag should be used in
conjunction with the <code> tag.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>
</p>
<p>
</p>
</body>
</html>
Explanation:
<sub> (subscript):
<sup> (superscript):
Ordered List
HTML
<!DOCTYPE html>
<html>
<head>
<title>Baking a Cake</title>
</head>
<body>
<ol type="1">
<li>Let it cool.</li>
<li>Enjoy!</li>
</ol>
<h2>Steps to Bake a Cake (Uppercase Letters)</h2>
<ol type="A">
<li>Let it cool.</li>
<li>Enjoy!</li>
</ol>
<ol type="a">
<li>Let it cool.</li>
<li>Enjoy!</li>
</ol>
<li>Let it cool.</li>
<li>Enjoy!</li>
</ol>
<ol type="i">
<li>Let it cool.</li>
<li>Enjoy!</li>
</ol>
</body>
</html>
Explanation:
The code creates five ordered lists, each with the same cake-baking
steps, but with a different numbering style.
Question 2: Write an ordered list where each list item contains another
ordered list (nested list). Example: 1. Fruits 1. Apple 2. Banana 3.
Orange
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol>
<li>Fruits
<ol type="a">
<li>Apple</li>
<li>Banana</li>
<li>Orange</li>
</ol>
</li>
<li>Vegetables
<ol type="a">
<li>Carrot</li>
<li>Broccoli</li>
<li>Spinach</li>
</ol>
</li>
<li>Desserts
<ol type="a">
<li>Chocolate Cake</li>
<li>Ice Cream</li>
<li>Cookies</li>
</ol>
</li>
</ol>
</body>
</html>
Explanation:
How it Works:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Car Types</title>
</head>
<body>
<li>Sedan</li>
<li>SUV</li>
<li>Hatchback</li>
<li>Convertible</li>
</ul>
<li>Sedan</li>
<li>SUV</li>
<li>Hatchback</li>
<li>Convertible</li>
</ul>
<li>Sedan</li>
<li>SUV</li>
<li>Hatchback</li>
<li>Convertible</li>
</ul>
<li>Sedan</li>
<li>SUV</li>
<li>Hatchback</li>
<li>Convertible</li>
</ul>
</body>
</html>
style="list-style-type: ...":
o This is an inline CSS style attribute used to set the bullet style.
Key points:
The type attribute for <ul> is deprecated in HTML5. Use CSS list-
style-type instead.
The example above shows how to use inline styles. For better code
organization and maintainability, it is recommended to use external
or internal CSS stylesheets.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Countries and Tourist Attractions</h2>
<ul>
<li>France
<ul>
<li>Eiffel Tower</li>
<li>Louvre Museum</li>
</ul>
</li>
<li>Italy
<ul>
<li>Colosseum</li>
<li>Vatican City</li>
</ul>
</li>
<li>Japan
<ul>
<li>Tokyo Tower</li>
<li>Kyoto Temples</li>
<li>Mount Fuji</li>
</ul>
</li>
<li>United States
<ul>
<li>Statue of Liberty</li>
<li>Grand Canyon</li>
</li>
</ul>
</body>
</html>
Explanation:
How it Works:
12.Definition List
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Web Technologies</h2>
<dl>
<dt>HTML</dt>
<dt>CSS</dt>
<dt>JavaScript</dt>
<dt>Python</dt>
</dl>
</body>
</html>
Explanation:
<dl> (Definition List): This tag defines the overall definition list.
<dt> (Definition Term): This tag defines the term being defined
(e.g., HTML, CSS, JavaScript, Python).
How it Works:
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<dl>
<dt>HTML</dt>
<dt>CSS</dt>
<dd style="font-family: 'Verdana', sans-serif; background-color:
#e0f2f7; padding: 5px;">Cascading Style Sheets: A style sheet
language used for describing the presentation of a document written in
HTML or XML.</dd>
<dt>JavaScript</dt>
<dt>Python</dt>
</dl>
</body>
</html>
1. Inline CSS:
2. font-family:
3. background-color:
4. padding:
13. Linking
Question 1: Create a navigation menu with links to Home, About,
Services, and Contact Us using an unordered list.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Navigation Menu</title>
<style>
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
background-color: #f1f1f1;
overflow: hidden;
}
nav li {
float: left;
}
nav li a {
display: block;
color: #333;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
nav li a:hover {
background-color: #ddd;
}
</style>
</head>
<body>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</nav>
</body>
</html>
Explanation:
1. <!DOCTYPE html>: Declares the document type as HTML5.
2. <html>: The root element of an HTML page.
3. <head>: Contains meta-information about the HTML page.
o <title>: Specifies a title for the HTML page.
o <style>: Contains CSS styles to format the navigation menu.
nav ul: Removes default list styling, margins, and
padding. Sets background color and overflow.
nav li: Floats list items to create a horizontal menu.
nav li a: Styles the links as block elements, sets colors,
alignment, padding, and removes underlines.
nav li a:hover: Changes the background color on hover.
4. <body>: Contains the visible page content.
5. <nav>: Defines a section of navigation links.
6. <ul>: Defines an unordered list for the navigation menu.
7. <li>: Defines list items (navigation links).
8. <a>: Defines hyperlinks.
o href: Specifies the URL of the linked page.
o The link text (e.g., "Home") is displayed to the user.
9. Important:
o Replace "index.html", "about.html", "services.html", and
"contact.html" with the actual file paths of your pages.
o The CSS styles provide a basic horizontal navigation menu.
You can customize the styles to match your design
preferences.
o This example uses an internal style sheet. For larger projects,
external style sheets are recommended.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Table of Contents with Bookmarks</title>
<style>
body {
font-family: sans-serif;
}
#toc {
background-color: #f0f0f0;
padding: 10px;
margin-bottom: 20px;
}
section {
padding: 20px;
border-bottom: 1px solid #ddd;
}
</style>
</head>
<body>
<div id="toc">
<h2>Table of Contents</h2>
<ul>
<li><a href="#section1">Section 1 - Introduction</a></li>
<li><a href="#section2">Section 2 - Main Content</a></li>
<li><a href="#section3">Section 3 - Conclusion</a></li>
</ul>
</div>
<section id="section1">
<h2>Section 1 - Introduction</h2>
<p>This is the introduction section of the page. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat.</p>
<p>More intro text here.</p>
</section>
<section id="section2">
<h2>Section 2 - Main Content</h2>
<p>This is the main content section. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.</p>
<p>More main content text here.</p>
<p>Even more main content text here.</p>
</section>
<section id="section3">
<h2>Section 3 - Conclusion</h2>
<p>This is the conclusion section. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.</p>
<p>More conclusion text here.</p>
</section>
</body>
</html>
Explanation:
1. Table of Contents (TOC):
o A div with id="toc" is created to hold the table of contents.
o An unordered list (<ul>) is used to create the list of links.
o Each list item (<li>) contains an anchor tag (<a>).
o The href attribute of each anchor tag uses the # symbol
followed by the id of the corresponding section (e.g.,
href="#section1").
2. Sections:
o section elements are used to divide the page into distinct
sections.
o Each section has a unique id attribute (e.g., id="section1").
This id is the target of the bookmark links.
o The section elements contain headings (<h2>) and
paragraphs (<p>) with content.
3. CSS:
o Basic CSS is added to style the TOC and sections.
o The TOC has a light gray background.
o Sections have padding and a bottom border to separate them.
4. How it Works:
o When a link in the TOC is clicked, the browser smoothly scrolls
to the section with the matching id.
o This provides a convenient way to navigate long pages.
o The sections are styled to provide visual separation.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Link Types</title>
</head>
<body>
<h1>Link Examples</h1>
<p>
</p>
<p>
</p>
<p>
<a href="mailto:contact@example.com">Email Us (Mailto Link)</a>
</p>
</body>
</html>
Explanation:
o Relative links are used for linking to pages within the same
website.
14. Tables
Question 1: Create a table that displays a weekly class schedule,
where: • Rows represent days (Monday to Friday). • Columns
represent subjects.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border-collapse: collapse;
padding: 8px;
text-align: center;
th {
background-color: #f2f2f2;
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Day</th>
<th>Math</th>
<th>Science</th>
<th>English</th>
<th>History</th>
</tr>
</thead>
<tbody>
<tr>
<td>Monday</td>
<td>9:00 AM</td>
<td>10:00 AM</td>
<td>11:00 AM</td>
<td>1:00 PM</td>
</tr>
<tr>
<td>Tuesday</td>
<td>10:00 AM</td>
<td>11:00 AM</td>
<td>1:00 PM</td>
<td>2:00 PM</td>
</tr>
<tr>
<td>Wednesday</td>
<td>9:00 AM</td>
<td>1:00 PM</td>
<td>2:00 PM</td>
<td>11:00 AM</td>
</tr>
<tr>
<td>Thursday</td>
<td>2:00 PM</td>
<td>9:00 AM</td>
<td>10:00 AM</td>
<td>1:00 PM</td>
</tr>
<tr>
<td>Friday</td>
<td>11:00 AM</td>
<td>2:00 PM</td>
<td>9:00 AM</td>
<td>10:00 AM</td>
</tr>
</tbody>
</table>
</body>
</html>
Explanation:
4. CSS:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Conference Agenda</title>
<style>
table, th, td {
border-collapse: collapse;
padding: 8px;
text-align: left;
th {
background-color: #f2f2f2;
</style>
</head>
<body>
<h2>Conference Agenda</h2>
<table>
<thead>
<tr>
<th>Time</th>
<th>Session</th>
<th>Speaker</th>
</tr>
</thead>
<tbody>
<tr>
</tr>
<tr>
</tr>
<tr>
<td>John Doe</td>
</tr>
<tr>
<td>Alice Johnson</td>
</tr>
<tr>
</tr>
<tr>
<td>Panel of Experts</td>
</tr>
<tr>
<td>Some Speaker</td>
</tr>
<tr>
<td>Another Speaker</td>
</tr>
</tbody>
</table>
</body>
</html>
Explanation:
colspan="2":
rowspan="2":
Table Structure:
CSS:
o Basic CSS is applied to add borders, collapse borders, add
padding, and style the header cells.
The example shows how rowspan and colspan can be used to create
complex table layouts.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Student Records</title>
<style>
table, th, td {
border-collapse: collapse;
padding: 8px;
text-align: left;
th {
background-color: #f2f2f2;
</style>
</head>
<body>
<h2>Student Records</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
<tr>
<td>12345</td>
<td>Alice Smith</td>
<td>16</td>
<td>A</td>
</tr>
<tr>
<td>67890</td>
<td>Bob Johnson</td>
<td>17</td>
<td>B+</td>
</tr>
<tr>
<td>13579</td>
<td>Charlie Brown</td>
<td>15</td>
<td>C</td>
</tr>
</tbody>
</table>
</body>
</html>
Explanation:
4. CSS:
15. Images
Question 1: Display an image using the <img> tag and adjust the
height and width using inline CSS.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Image Display</h2>
</body>
</html>
o The width is set to 500 pixels, and the height is set to 300
pixels. You can modify these values as needed.
5. File Path:
7. CSS Best Practices: While inline CSS is used in this example for
simplicity, it's generally better practice to use external or internal
stylesheets for larger projects. This allows for better organization
and maintainability of your CSS code.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Images in Table</title>
<style>
table {
td {
img {
</style>
</head>
<body>
<table>
<tr>
</tr>
</table>
</body>
</html>
Table Structure:
Images:
CSS:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Image Link</title>
</head>
<body>
<h2>Clickable Image</h2>
</a>
</body>
</html>
Explanation:
o The <img> tag is placed inside the <a> tag, making the
image clickable.
3. Paragraph:
4. File Paths:
5. Accessibility:
6. URL:
Question 1: Embed an MP3 file with controls so the user can play,
pause, and adjust volume.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Audio Player</title>
</head>
<body>
<audio controls>
</audio>
</body>
</html>
Explanation:
1. <audio> Tag:
2. <source> Tag:
o The <source> tag specifies the audio file and its type.
o src="your_audio.mp3": This attribute specifies the path to the
MP3 file. Replace "your_audio.mp3" with the actual
filename and path of your audio file.
3. Fallback Text:
o "Your browser does not support the audio element." This text
is displayed if the user's browser doesn't support the <audio>
tag.
4. File Path:
Question 2: Embed a YouTube video inside an HTML page using the tag.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</html>
o The src attribute now uses the correct YouTube embed URL
format: https://www.youtube.com/embed/VIDEO_ID.
4. title:
5. frameborder:
6. allow:
7. allowfullscreen:
8. Replace VIDEO_ID:
o Remember to replace VIDEO_ID with the actual ID of
the YouTube video.
9. Example:
HTML
Question 3: Write an HTML page with an MP4 video, ensuring it: • Has
controls • Autoplays when the page loads • Loops continuously
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</video>
</body>
</html>
Explanation:
1. <video> Tag:
2. controls Attribute:
3. autoplay Attribute:
4. loop Attribute:
6. <source> Tag:
o The <source> tag specifies the video file and its type.
7. Fallback Text:
o "Your browser does not support the video tag." This text is
displayed if the user's browser doesn't support the <video>
tag.
8. File Paths: