HTML & CSS MCQS
HTML & CSS MCQS
Answer:-
Certainly, here are both multiple-choice questions (MCQs) and a practical task related to HTML
and the World Wide Web:
**Multiple-Choice Questions (MCQs)
1. What does HTML stand for?
a) Hyper Text Markup Language
b) High-Level Text Markup Language
c) Hyperlink and Text Markup Language
d) Hypertext Transfer Protocol
2. Which of the following HTML tags is used to create a hyperlink?
a) <link>
b) <a>
c) <hyperlink>
d) <url>
3. What does CSS stand for in web development?
a) Computer Style Sheets
b) Cascading Style Sheets
c) Creative Style Sheets
d) Coding Style Sheets
4. Which HTML element is used for creating an unordered list?
a) <ul>
b) <ol>
c) <li>
d) <dl>
5. Which file extension is commonly used for HTML files?
a) .html
b) .css
c) .js
d) .jpg
**Practical Task: Create a Simple HTML Webpage**
Create a basic HTML webpage with the following elements:
1. Title: "My First Webpage"
2. Heading: "Welcome to My First Webpage"
3. Paragraph: "This is a simple webpage created using HTML."
4. An image of your choice (you can use an image URL or upload an image to your project
folder).
5. A hyperlink to any website of your choice.
Question no 2
Website
ANSWER:-
A website is a collection of webpages that are interconnected and hosted on the World Wide
Web (WWW) and accessible through a web browser. Websites are used to present
information, provide services, or promote products and can vary widely in content and
purpose.
**Multiple-Choice Questions (MCQs):**
1. What is a website?
a) A physical server
b) A collection of webpages
c) A type of software
d) A web browser
2. Which technology is primarily used to create the structure and content of webpages on a
website?
a) JavaScript
b) CSS (Cascading Style Sheets)
c) HTML (Hypertext Markup Language)
d) PHP (Hypertext Preprocessor)
4. What does WWW stand for in the context of the internet and websites?
a) World Weather Watch
b) World Wide Web
c) Web Widget Wizard
d) Web Wireless Wonders
Question no 3
Web Pages
Answer
Web pages are individual documents or files that are part of a website and are
displayed in a web browser when accessed by a user. They contain content such as text,
images, multimedia elements, and hyperlinks. Web pages are written in languages like HTML
(Hypertext Markup Language), and they are the fundamental building blocks of websites.
**Multiple-Choice Questions (MCQs):**
1. What are web pages?
a) Small applications
b) Individual documents in a website
c) Web browsers
d) Social media platforms
2. Which programming language is commonly used to create the structure and content of
web pages?
a) PHP
b) JavaScript
c) HTML
d) Python
3. What is the primary purpose of web pages?
a) To host email accounts
b) To display content on the World Wide Web
c) To store data in a database
d) To run video games
4. Which software is used to view and interact with web pages?
a) Web server
b) Web browser
c) Web hosting provider
d) Web framework
5. What is the typical file extension for web page documents?
a) .txt
b) .web
c) .html
d) .pdf
**Practical Task: Create a Basic Web Page**
Create a basic web page using HTML. Your web page should include the following elements:
1. Title: "My First Web Page"
2. Heading: "Welcome to My Web Page"
3. A paragraph describing your interests or a topic of your choice.
4. An image related to the topic or your interests.
5. A hyperlink to a website you find interesting.
Question no 4:
Different types of websites
Answer
Answer
Question no 6:
Difference between Frontend &
Backend Language
Answer
Certainly! Let's explore the differences between frontend and
backend languages through multiple-choice questions (MCQs) and a practical
task.
**Multiple-Choice Questions (MCQs):**
1. Which part of a web application is primarily responsible for the user interface
and how the website looks and feels?
a) Backend
b) Frontend
c) Middleware
d) Full-stack
2. Which of the following languages is commonly associated with frontend
development?
a) Python
b) Ruby
c) JavaScript
d) PHP
3. What is the primary focus of frontend languages and technologies?
a) Handling server-side logic and databases
b) Managing user interactions and presentation
c) Controlling server security
d) Generating API endpoints
4. Backend languages are responsible for:
a) Designing user interfaces
b) Handling server-side business logic and data storage
c) Controlling browser behavior
d) Managing web page layouts
5. Which of the following is a common task for frontend developers?
a) Optimizing database queries
b) Creating API endpoints
c) Styling web pages and handling user interactions
d) Managing server security
Question no 7
What Is HTML?
Answer
2. **Text Formatting**:
- `<h1>`, `<h2>`, `<h3>`, ... `<h6>`: Headings for organizing content by
importance.
- `<p>`: Paragraphs for text content.
- `<br>`: Line breaks.
- `<hr>`: Horizontal lines for separating content.
3. **Lists**:
- `<ul>`: Unordered lists.
- `<ol>`: Ordered lists.
- `<li>`: List items within `<ul>` or `<ol>`.
4. **Links and Anchors**:
- `<a>`: Anchor tags for creating hyperlinks.
5. **Images**:
- `<img>`: Embeds images on a webpage.
6. **Tables**:
- `<table>`: Defines a table.
- `<tr>`: Defines a table row.
- `<td>`: Defines a table cell (data).
- `<th>`: Defines a table header cell.
7. **Forms**:
- `<form>`: Creates a form to collect user input.
- `<input>`: Defines various input types (text, password, radio buttons,
checkboxes, etc.).
- `<button>`: Creates buttons for form submission.
- `<select>`: Defines dropdown select lists.
- `<textarea>`: Creates a multi-line text input area.
8. **Semantic Elements**:
- `<header>`, `<nav>`, `<main>`, `<article>`, `<section>`, `<aside>`, `<footer>`:
Semantic elements that provide meaning to the structure of a webpage.
**Multiple-Choice Questions (MCQs):**
1. What is the purpose of the `<meta>` element in HTML?
a) Define a hyperlink
b) Provide metadata about the document
c) Display an image
d) Create a list
2. Which HTML tag is used to create a numbered list?
a) `<ul>`
b) `<ol>`
c) `<li>`
d) `<a>`
3. Which HTML tag is used to display an image on a webpage?
a) `<img>`
b) `<ul>`
c) `<a>`
d) `<p>`
4. What is the purpose of the `<form>` element in HTML?
a) Define a table
b) Create a hyperlink
c) Create a web form for user input
d) Display metadata
Question no 9
Basic HTML Page Structure
Answer
The basic HTML page structure consists of essential elements that are used to
create a standard webpage. Here's the typical structure:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Page Title</title>
</head>
<body>
<!-- Content goes here -->
</body>
</html>
```
Let's include multiple-choice questions (MCQs) and a practical task related to
the basic HTML page structure.
**Multiple-Choice Questions (MCQs):**
1. What is the purpose of the `<!DOCTYPE html>` declaration in HTML?
a) It defines the character encoding of the document.
b) It specifies the version of HTML being used.
c) It declares the document as an HTML5 document.
d) It provides a title for the webpage.
2. What is the role of the `<head>` element in an HTML document?
a) It contains the main content of the webpage.
b) It defines the page's structure and layout.
c) It holds metadata and links to external resources.
d) It displays visible text on the webpage.
3. Which HTML tag is used to specify the character encoding of the document?
a) `<meta>`
b) `<head>`
c) `<title>`
d) `<body>`
4. What is the purpose of the `<title>` element in the `<head>` section of an
HTML document?
a) It defines the primary heading of the webpage.
b) It provides a title for the browser's title bar or tab.
c) It creates a hyperlink to another webpage.
d) It sets the background color of the webpage.
**Practical Task: Create a Basic HTML Page**
Create a basic HTML page with the following structure:
1. Set the document type declaration to HTML5.
2. Define the character encoding as UTF-8.
3. Give the page a title such as "My Basic HTML Page."
4. Add a heading in the `<body>` section with the text "Welcome to My Page."
5. Create a paragraph in the `<body>` section with a brief description of your
interests or a topic of your choice.
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Page Title</title>
</head>
<body>
<!-- Content goes here -->
</body>
</html>
Question no 10
Headings & Paragraphs
Answer:
Headings and paragraphs are essential HTML elements used for structuring
content on a webpage. Headings are used to define the hierarchy and titles of
different sections, while paragraphs are used to display text content.
**Multiple-Choice Questions (MCQs):**
Question no 11
HTML Formatting
Answer
HTML Formatting refers to the use of HTML tags and attributes to
control the appearance and style of text and elements on a webpage. It allows
web developers to format text, change fonts, adjust text alignment, create lists,
and apply various visual effects. Here are some common HTML formatting
elements:
**HTML Formatting Tags and Attributes:**
1. `<strong>` and `<em>`: Used for strong (bold) and emphasized (italic) text,
respectively.
2. `<u>`: Underlines text.
3. `<s>`: Strikes through text to indicate deletion or no longer relevant
information.
4. `<sub>` and `<sup>`: Creates subscript and superscript text.
5. `<blockquote>`: Defines a block of text as a quotation.
6. `<code>`: Displays inline code or computer code.
7. `<pre>`: Preserves white spaces and line breaks for displaying preformatted
text.
8. `<br>`: Inserts a line break within text.
9. `<hr>`: Adds a horizontal line or rule.
Question no 12
HTML Attributes
Answer
HTML attributes are additional pieces of information that can be
added to HTML elements to modify their behavior or provide extra information
about them. Attributes are specified within the opening tag of an HTML element
and are written as name-value pairs. Here are some common HTML attributes:
**Common HTML Attributes:**
1. **class**: Specifies one or more CSS classes that an element belongs to.
2. **id**: Provides a unique identifier for an element.
3. **src**: Specifies the source URL for elements like images and iframes.
4. **href**: Specifies the URL for hyperlinks.
5. **alt**: Defines alternative text for images (useful for accessibility).
6. **title**: Provides a title or tooltip for elements like links and images.
7. **style**: Defines inline CSS styles for an element.
8. **target**: Specifies where to open linked documents (e.g., in a new tab or
window).
**Inline Elements:**
- Inline elements are used within block-level elements to style or modify the
content of a block-level element.
- They do not start on a new line; they flow within the content.
- Inline elements create "inline" content within a block.
- Examples of inline elements include `<span>`, `<a>`, `<strong>`, `<em>`,
`<img>`, `<br>`, `<input>`, and more.
**Multiple-Choice Questions (MCQs) with Correct Answers Marked:**
1. Which type of HTML element is used to create the main structure of a
webpage?
a) Block-level elements **(Correct)**
b) Inline elements
c) Metadata elements
d) Semantic elements
2. How do block-level elements typically appear in relation to other content?
a) They flow within the content.
b) They start on a new line and stretch the full width of their parent container.
**(Correct)**
c) They create inline content within a block.
d) They do not affect the layout of the page.
3. Which type of HTML element is used within block-level elements to style or
modify content?
a) Block-level elements
b) Inline elements **(Correct)**
c) Metadata elements
d) Semantic elements
Question no 14
HTML Tag vs. Element
Answer
Question no 15
HTML Image & Link
Answer
HTML Image and Link elements are essential for embedding images and
creating hyperlinks in webpages. Let's explore these elements with multiple-
choice questions (MCQs) and a practical task.
**HTML Image (`<img>`) Element:**
The HTML `<img>` element is used to embed images in a webpage.
**HTML Link (`<a>`) Element:**
The HTML `<a>` (anchor) element is used to create hyperlinks to other
webpages or resources.
**Multiple-Choice Questions (MCQs) with Correct Answers Marked:**
1. What is the purpose of the HTML `<img>` element?
a) To create hyperlinks.
b) To display images. **(Correct)**
c) To format text.
d) To define a table.
2. Which attribute of the `<img>` element specifies the source URL of the
image?
a) `alt`
b) `link`
c) `src` **(Correct)**
d) `href`
3. What does the `alt` attribute in the `<img>` element provide?
a) The title of the image.
b) The image's width and height.
c) A brief description or alternative text for the image. **(Correct)**
d) The image's file size.
5. Which attribute of the `<a>` element specifies the URL to which the hyperlink
should navigate?
a) `href` **(Correct)**
b) `src`
c) `link`
d) `target`
2. Embed an image using the `<img>` element. You can use any image you like,
and make sure to specify the `src` and `alt` attributes.
3. Create a hyperlink using the `<a>` element that links to a website of your
choice. Specify the `href` attribute.
4. Add a descriptive text near the image and hyperlink to provide context.
5. Save the file with an ".html" extension and open it in a web browser to view
your HTML document with the image and hyperlink.
Question no 16
HTML Table
Answer
An HTML table is a structured way of organizing data in rows and columns on a
webpage. Tables are created using the `<table>` element and consist of multiple
sub-elements, including `<tr>` (table row), `<th>` (table header cell), and `<td>`
(table data cell). Tables are commonly used for displaying data in a tabular
format.
2. Create an HTML table using the `<table>` element. The table should have at
least three rows and three columns.
3. Add a table header row (`<tr>`) with `<th>` elements to define column
headers.
4. Populate the table with data using `<td>` elements for the remaining rows
and columns.
5. Add some sample data to the table, such as names, ages, and locations.
6. Save the file with an ".html" extension and open it in a web browser to view
your HTML table.
Question no 17
HTML Lists
Answer
HTML lists are used to organize and present information in a
structured format on webpages. There are three main types of HTML lists:
ordered lists (`<ol>`), unordered lists (`<ul>`), and definition lists (`<dl>`). Lists
can contain list items (`<li>`), which are the individual items or entries within a
list.
2. Create an ordered list (`<ol>`) with at least three list items (`<li>`). You can
use any content you like.
3. Create an unordered list (`<ul>`) with at least three list items (`<li>`). Again,
use any content you prefer.
4. Create a definition list (`<dl>`) with at least three term-definition pairs (`<dt>`
and `<dd>`).
6. Save the file with an ".html" extension and open it in a web browser to view
your HTML lists.
Question no 18
HTML Forms
Answer
HTML forms are a crucial part of web development, allowing
users to input and submit data to websites. Forms are created using the
`<form>` element and can contain various form elements such as text fields,
radio buttons, checkboxes, and buttons. Forms are used for user interactions
like submitting contact information, performing searches, or completing online
surveys.
3. What type of HTML input element is typically used for single-line text input?
a) `<textarea>`
b) `<text>`
c) `<input type="text">` **(Correct)**
d) `<textfield>`
4. Which HTML input type is used to create a checkbox?
a) `<input type="radio">`
b) `<input type="checkbox">` **(Correct)**
c) `<input type="text">`
d) `<input type="button">`
5. Save the file with an ".html" extension and open it in a web browser to view
your HTML form.
Question no 19
HTML Layout Elements
Answer
HTML layout elements are used to structure and organize the
content on a webpage. These elements help define the layout and arrangement
of different sections within a webpage, such as headers, navigation menus,
main content, sidebars, and footers. Common HTML layout elements include
`<header>`, `<nav>`, `<main>`, `<article>`, `<section>`, `<aside>`, and `<footer>`.
2. Create a layout structure using HTML layout elements. Your layout should
include the following sections:
- A `<header>` for the website header.
- A `<nav>` for the navigation menu.
- A `<main>` for the main content of the webpage.
- An `<aside>` for additional content (e.g., a sidebar).
- An `<article>` for a standalone piece of content.
- A `<section>` for a related section within the main content.
- A `<footer>` for the website footer.
4. Style the layout using CSS if you'd like to enhance its appearance.
5. Save the file with an ".html" extension and open it in a web browser to view
your HTML layout.
Question no 21
HTML Iframe
ANSWER
An HTML `<iframe>` (short for "inline frame") is an HTML element
used to embed another HTML document or external web content within a
webpage. `<iframe>` elements are commonly used to display external web
pages, videos, maps, or other content within the context of the host webpage.
Here are some multiple-choice questions (MCQs) and a practical task to
demonstrate the usage of `<iframe>` elements.
2. Which attribute of the `<iframe>` element specifies the source URL of the
content to be displayed within the frame?
a) `srcdoc`
b) `href`
c) `source`
d) `src` **(Correct)**
3. How can you specify the dimensions (width and height) of an `<iframe>`
element?
a) Using CSS styles.
b) By adjusting the `border` attribute.
c) By setting the `size` attribute.
d) By using the `width` and `height` attributes. **(Correct)**
3. Specify the `width` and `height` attributes to define the dimensions of the
iframe.
4. Use the `allowfullscreen` attribute to enable fullscreen mode for the iframe (if
applicable).
6. Save the file with an ".html" extension and open it in a web browser to view
your webpage with the embedded iframe.
This task will help you practice embedding external web content using the HTML
`<iframe>` element and provide alternative content for browsers that do not
support iframes.
Question no 22
HTML Media Elements
Answer
HTML media elements are used to embed and display various
types of multimedia content within a webpage. These elements allow you to
include images, audio, video, and other multimedia files in your web
documents. Common HTML media elements include `<img>` for images,
`<audio>` for audio files, and `<video>` for video files.
**Multiple-Choice Questions (MCQs) with Correct Answers Marked:**
3. What HTML element is typically used to embed and play audio files on a
webpage?
a) `<audio>` **(Correct)**
b) `<sound>`
c) `<music>`
d) `<media>`
4. Which attribute of the `<video>` element specifies the source URL of the
video file to be played?
a) `srcdoc`
b) `source`
c) `video-src`
d) `src` **(Correct)**
2. Embed an image using the `<img>` element. You can use any image you like,
and make sure to specify the `src` and `alt` attributes.
3. Include an audio player using the `<audio>` element. Embed an audio file
(e.g., an MP3 file) and use the `controls` attribute to display the player controls.
4. Embed a video player using the `<video>` element. Use a video file (e.g., an
MP4 file) and include the `controls` attribute to display video player controls.
5. Save the file with an ".html" extension and open it in a web browser to view
your webpage with the embedded media elements.
(css)
Question no 1
What is CSS?
Answer
5. What does the term "cascading" in Cascading Style Sheets (CSS) refer to?
a) It refers to the ability to create animations.
b) It signifies the hierarchical nature of CSS rules and how they are applied.
**(Correct)**
c) It indicates the use of color gradients in styles.
d) It represents the process of compressing styles for faster loading.
**Practical Task: Create a CSS Style**
Create an HTML document and a CSS stylesheet with the following content:
**HTML Document:**
1. Set the title of the webpage to "CSS Introduction."
**CSS Stylesheet:**
1. Style the heading element to change its text color, font size, and text
alignment.
4. Save the CSS file with a ".css" extension and link it to the HTML document
using the `<link>` element in the document's `<head>` section.
5. Open the HTML file in a web browser to view the styled heading.
Question no 3
CSS Syntax
Answer
**CSS (Cascading Style Sheets) Syntax** refers to the rules
and structure for writing CSS code, which is used to define the visual style and
layout of HTML elements on a webpage. CSS syntax consists of selectors,
properties, and values. Selectors specify which HTML elements should be styled,
properties define what styles to apply, and values specify the specific values for
those styles. Here are some multiple-choice questions (MCQs) and a practical
task to understand CSS syntax:
2. Which part of a CSS rule determines which HTML elements the rule applies
to?
a) Properties
b) Values
c) Selectors **(Correct)**
d) Declarations
5. Which CSS symbol is used to separate a property and its value within a CSS
rule?
a) Semicolon (;) **(Correct)**
b) Colon (:)
c) Comma (,)
d) Period (.)
2. Link the CSS file to the HTML document using the `<link>` element in the
document's `<head>` section.
3. Open the HTML file in a web browser to view the styled heading.
Code:
Question no 4
Selector Types
Answer
In CSS, selectors are patterns that are used to select and target
HTML elements in order to apply styles to them. There are various types of
selectors that allow you to specify which elements should be styled. Here are
some common types of selectors along with multiple-choice questions (MCQs)
and a practical task to help you understand selector types:
1. **Type Selector:** Selects elements based on their HTML tag name. For
example, `p` selects all `<p>` (paragraph) elements.
3. **ID Selector:** Selects a single element based on the value of its `id`
attribute. For example, `#header` selects the element with `id="header"`.
2. Which CSS selector targets elements based on their HTML tag name?
a) Class Selector
b) Type Selector **(Correct)**
c) ID Selector
d) Universal Selector
1. Use a type selector to change the color of all paragraphs (`<p>`) to red.
2. Use a class selector to style all elements with the class `special` by giving
them a background color of yellow.
5. Use a universal selector to set a margin and padding for all elements on the
page.
Question no 5
CSS Rules Overriding
Answer
**CSS (Cascading Style Sheets) Rules Overriding** refers
to the process by which conflicting CSS rules are applied to the same HTML
element, and the browser determines which rule takes precedence. CSS rules
can override each other based on specificity, importance, and source order.
Let's explore this concept with multiple-choice questions (MCQs) and a practical
task.
1. What is the term used to describe the process of resolving conflicting CSS
rules?
a) Cascading
b) Overloading
c) Overriding
d) Inheriting
**Answer: c) Overriding**
3. In the event of conflicting CSS rules, which rule typically takes precedence?
a) The rule with the lowest specificity.
b) The rule with the highest specificity. **(Correct)**
c) The rule with the longest selector.
d) The rule defined in the last-loaded stylesheet.
2. Use the `!important` declaration in one of the CSS rules to demonstrate its
impact on rule overriding.
3. Include comments in your CSS file to describe which rules are expected to
override others and why.
4. Observe the results in a web browser to see how CSS rules are applied, taking
into account specificity, importance, and source order.
Question no 6
CSS Comments
Answer
**CSS (Cascading Style Sheets) Comments** are non-
executable lines of text within a CSS file that provide explanations, notes, or
annotations about the code. Comments are ignored by web browsers and are
solely for human readers, such as developers, to understand the code better
and make it more maintainable. They are enclosed within special markers and
do not affect the styling of web content. Let's explore CSS comments with
multiple-choice questions (MCQs) and a practical task.
h1 {
color: blue; /* Set text color to blue */
font-size: 24px; /* Set font size to 24 pixels */
}
p{
color: green; /* Set text color to green */
}
1. In the CSS file, add comments to describe the purpose or intention of each
CSS rule. Use comments to explain the styling choices for the `h1` and `p`
elements.
3. Open the HTML file in a web browser to view the web page. Notice that the
comments do not affect the appearance of the page but provide helpful
explanations for developers.
Code:
Html
<!DOCTYPE html>
<html>
<head>
<title>CSS Comments Example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Hello, CSS Comments!</h1>
<p>This is a sample webpage.</p>
</body>
</html>
Code css:
/* This is a CSS comment */
/* Add comments to describe the purpose of each rule below */
h1 {
color: blue; /* Set text color to blue */
font-size: 24px; /* Set font size to 24 pixels */
}
p{
color: green; /* Set text color to green */
}
Create an HTML document and an external CSS file with the following content:
p{
background-color: lightgray;
}
```
1. In the CSS file, set the text color of the `<h1>` element to "green."
3. Add any additional CSS rules to experiment with different colors and
properties.
5. Open the HTML file in a web browser to view the webpage with the applied
color styles.
By completing this task, you'll practice using CSS to apply colors to HTML
elements, helping you understand how to control the visual appearance of web
content.
Code html
<!DOCTYPE html>
<html>
<head>
<title>CSS Colors Example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Welcome to CSS Colors</h1>
<p>This is a sample text with various colors.</p>
</body>
</html>
Code css:_
h1 {
color: blue;
}
p{
background-color: lightgray;
}
Question no 8
CSS Backgrounds
Answer
**CSS Backgrounds** refer to the CSS properties and techniques
used to set and control the background styling of HTML elements. Backgrounds
can include colors, images, patterns, and other visual elements that enhance the
appearance of a webpage. Let's explore CSS backgrounds with multiple-choice
questions (MCQs) and a practical task.
Create an HTML document and an external CSS file with the following content:
1. In the CSS file, set the background image of the `<h1>` element to an image of
your choice. You can use a local image file or provide a valid URL to an image on
the web.
2. Adjust the `background-repeat` and `background-size` properties for the
`<h1>` element to control how the background image is displayed.
3. Add any additional CSS rules to experiment with different background colors,
images, or properties.
5. Open the HTML file in a web browser to view the webpage with the applied
background styles.
Question no 9
CSS Borders
Answer
**CSS Borders** refer to the CSS properties and
techniques used to define and style the borders of HTML elements. Borders can
be applied to various HTML elements such as divs, paragraphs, images, and
more. CSS allows you to control the border width, color, style, and radius, giving
you flexibility in creating visually appealing designs. Let's explore CSS borders
with multiple-choice questions (MCQs) and a practical task.
5. How can you apply a border to all four sides of an element simultaneously in
CSS?
a) Use the `border` property followed by the desired width, style, and color.
**(Correct)**
b) Set the `border-top`, `border-right`, `border-bottom`, and `border-left`
properties separately.
c) Use the `border-all` property.
d) It's not possible to apply a border to all sides at once.
Create an HTML document and an external CSS file with the following content:
1. In the CSS file, set the border color of the `.box` element to a color of your
choice.
2. Adjust the border style of the `.box` element (e.g., `dashed`, `dotted`,
`double`) and experiment with different styles.
7. Open the HTML file in a web browser to view the webpage with the applied
border styles.
Question no 10
CSS Margins
Answer
**CSS Margins** are the CSS properties that control the space around
the outside of an HTML element, creating spacing between the element and its
surrounding elements. Margins can be used to add space between elements,
control the layout of web pages, and create visually appealing designs. Let's
explore CSS margins with multiple-choice questions (MCQs) and a practical task.
3. How can you set margins on all sides (top, right, bottom, left) of an element
simultaneously in CSS?
a) Use the `margin` property and specify a single value. **(Correct)**
b) Set `margin-top`, `margin-right`, `margin-bottom`, and `margin-left`
properties individually.
c) Use the `spacing` property.
d) Margins can only be applied to specific sides, not all at once.
5. In CSS, what happens when you set a negative margin value for an element?
a) The element's content expands.
b) The element is hidden from view.
c) The element overlaps with neighboring elements. **(Correct)**
d) The element's border becomes thicker.
**Practical Task: Apply CSS Margins**
Create an HTML document and an external CSS file with the following content:
1. In the CSS file, adjust the `margin` property of the `.box` element to
experiment with different margin values. Observe the effect on the spacing
around the element.
2. Add additional CSS rules to create margins for other elements or customize
the margins further.
4. Open the HTML file in a web browser to view the webpage with the applied
margin styles.
QUESTION NO 11
CSS Padding
Answer
**CSS Padding** refers to the CSS properties that control the
space between the content of an HTML element and its border. Padding creates
space inside an element, allowing you to control the distance between the
content and the element's edges. It is commonly used for adding space around
text and other content within an element. Let's explore CSS padding with
multiple-choice questions (MCQs) and a practical task.
1. In CSS, which property is used to control the space between the content of an
element and its border, creating padding?
a) `margin`
b) `spacing`
c) `border`
d) `padding` **(Correct)**
3. How can you set padding on all sides (top, right, bottom, left) of an element
simultaneously in CSS?
a) Use the `padding` property and specify a single value. **(Correct)**
b) Set `padding-top`, `padding-right`, `padding-bottom`, and `padding-left`
properties individually.
c) Use the `spacing` property.
d) Padding can only be applied to specific sides, not all at once.
5. In CSS, what happens when you set a negative padding value for an element?
a) The element's content expands.
b) The element is hidden from view.
c) The content overflows the element's borders. **(Correct)**
d) The element's border becomes thicker.
Create an HTML document and an external CSS file with the following content:
1. In the CSS file, adjust the `padding` property of the `.box` element to
experiment with different padding values. Observe the effect on the spacing
between the content and the element's edges.
2. Add additional CSS rules to create padding for other elements or customize
the padding further.
4. Open the HTML file in a web browser to view the webpage with the applied
padding styles.
Question no 12
CSS Height/Width
Answer
**CSS Height and Width** refer to the CSS properties used
to control the dimensions of HTML elements. These properties allow you to
specify the height and width of elements, defining how much space they occupy
within the web page layout. Let's explore CSS height and width with multiple-
choice questions (MCQs) and a practical task.
3. How can you specify the height and width of an element in CSS?
a) Use the `dimensions` property.
b) Set the `size` property.
c) Use the `height` and `width` properties separately. **(Correct)**
d) Specify the dimensions using the `dimension` attribute in the HTML.
4. What is the default unit of measurement for the `width` and `height`
properties in CSS?
a) Pixels (px)
b) Inches (in)
c) Centimeters (cm)
d) Auto (auto) **(Correct)**
5. In CSS, how can you make an element automatically adjust its width to fit the
available space within its parent container?
a) By setting a fixed width in pixels.
b) By using the `width` property with the value `auto`. **(Correct)**
c) By applying a percentage width relative to the parent container.
d) It's not possible to make an element adjust its width automatically.
Create an HTML document and an external CSS file with the following content:
/* Add your own CSS rules to experiment with height and width */
```
1. In the CSS file, adjust the `width` and `height` properties of the `.box` element
to experiment with different dimensions. Observe the effect on the size of the
element.
Question no 14
CSS Lists
Answer
**CSS Height and Width** refer to the CSS properties used to
control the dimensions of HTML elements. These properties allow you to specify
the height and width of elements, defining how much space they occupy within
the web page layout. Let's explore CSS height and width with multiple-choice
questions (MCQs) and a practical task.
4. What is the default unit of measurement for the `width` and `height`
properties in CSS?
a) Pixels (px)
b) Inches (in)
c) Centimeters (cm)
d) Auto (auto) **(Correct)**
5. In CSS, how can you make an element automatically adjust its width to fit the
available space within its parent container?
a) By setting a fixed width in pixels.
b) By using the `width` property with the value `auto`. **(Correct)**
c) By applying a percentage width relative to the parent container.
d) It's not possible to make an element adjust its width automatically.
Create an HTML document and an external CSS file with the following content:
**HTML Document (`index.html`):**
```html
<!DOCTYPE html>
<html>
<head>
<title>CSS Height and Width Example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="box">
<p>This is a sample box with specified dimensions.</p>
</div>
</body>
</html>
```
/* Add your own CSS rules to experiment with height and width */
```
1. In the CSS file, adjust the `width` and `height` properties of the `.box` element
to experiment with different dimensions. Observe the effect on the size of the
element.
4. Open the HTML file in a web browser to view the webpage with the applied
height and width styles.
Question no 15
CSS Tables
Answer
**CSS Tables** refer to the CSS properties and techniques used to
style HTML tables. HTML tables are used to organize and display data in rows
and columns, and CSS allows you to control their appearance, layout, spacing,
borders, and more. Let's explore CSS tables with multiple-choice questions
(MCQs) and a practical task.
**Multiple-Choice Questions (MCQs) with Correct Answers Marked:**
2. Which CSS property is used to set the border spacing between cells in a table?
a) `cell-spacing`
b) `border-spacing` **(Correct)**
c) `cell-margin`
d) `border-margin`
4. Which CSS property is used to set the background color for table rows or
table cells?
a) `table-background-color`
b) `row-background-color`
c) `cell-background-color`
d) `background-color` **(Correct)**
5. How can you center-align the content of a table cell horizontally using CSS?
a) Use the `text-align` property with the value `center` on the `td` or `th`
element. **(Correct)**
b) Apply the `center-content` class to the cell.
c) Use the `horizontal-align` property.
d) It's not possible to center-align table cell content.
Create an HTML document containing a table and an external CSS file to style
the table. Here's the starting code:
3. Add any additional CSS rules to further style the table, rows, or individual
cells as desired.
5. Open the HTML file in a web browser to view the webpage with the applied
table styles.
Question no 16
CSS Display
Answer
**CSS Display** is a CSS property that controls how an HTML
element is rendered or displayed on a web page. It determines the type of box
model used for an element, which affects its layout and positioning. CSS Display
allows you to change elements from their default block-level or inline behavior
to create different layouts and structures. Let's explore CSS Display with
multiple-choice questions (MCQs) and a practical task.
3. How can you make an element behave like a block-level element in CSS?
a) Use the `display: block;` property value. **(Correct)**
b) Apply the `block` class to the element.
c) Set the `block-element` property to `true`.
d) Elements cannot be made to behave like block-level elements.
4. Which `display` property value is used to hide an element from the layout
without affecting its existence in the DOM?
a) `block`
b) `inline`
c) `none` **(Correct)**
d) `hidden`
5. What is the purpose of the CSS `display: inline-block;` property value?
a) It creates a block-level element with inline characteristics.
b) It hides the element from view.
c) It allows elements to be displayed inline while maintaining block-level
characteristics, such as setting width and height. **(Correct)**
d) It vertically aligns the element's content.
Create an HTML document with multiple elements and use an external CSS file
to manipulate their display behavior. Here's the starting code:
1. In the CSS file, experiment with different `display` property values (`block`,
`inline`, `none`, `inline-block`) for each of the elements in the HTML document.
2. Observe how the display property affects the layout and positioning of each
element.
5. Open the HTML file in a web browser to view the webpage with the applied
display property styles.
By completing this task, you'll practice using CSS to control the display behavior
of HTML elements, allowing you to create various layouts and structures in your
web designs.
Question no 18
CSS Float
Answer
4. How can you clear floats in CSS to prevent content from wrapping around
them?
a) Use the `clear` property with a value of `center`.
b) Add extra padding to the floated elements.
c) Use the `clear` property with values like `left`, `right`, or `both`.
**(Correct)**
d) Clearing floats is not possible in CSS.
Create an HTML document that includes multiple elements and use the CSS
`float` property to control their positioning. Here's a simple example:
<div class="right-float">
<p>This text floats to the right of the image.</p>
<img src="right-image.jpg" alt="Right-Floated Image">
</div>
</body>
</html>
```
1. In the CSS file, experiment with different values for the `float` property (`left`,
`right`) for each of the elements in the HTML document.
2. Observe how the `float` property affects the layout and positioning of each
element.
3. Add the `.clear-float` class to any additional elements that need to clear
floats.
5. Open the HTML file in a web browser to view the webpage with the applied
float property styles.