HTML/CSS MCQ

HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 38

Multiple choice questions and answers (MCQs) on HTML/CSS to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as tags, web standards, CSS selector, objects, and more. This quiz will easily prepare anyone to pass their online test.
 
 

1. How do you embed a YouTube video into your HTML page using an <iframe> tag?

A <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"></iframe>

B <iframe src="https://www.youtube.com/watch?v=dQw4w9WgXcQ"></iframe>

C <video src="https://www.youtube.com/embed/dQw4w9WgXcQ"></video>

D <iframe src="https://youtube.com/video/dQw4w9WgXcQ"></iframe>

A
The URL of a YouTube video must be formatted as an “embed” URL to be used in an <iframe> tag.
 

2. What is the effect of the title attribute in an HTML tag?

A It sets the page title in the browser.

B It displays additional text when the user hovers over the element.

C It adds a caption to an image in an HTML document.

D It defines a title for form content.

B
The title attribute displays a tooltip when the user hovers over the element it is applied to. Example:

<p title="This is a paragraph">Hover over this text to see the tooltip.</p>

Output:

Hover over this text to see the tooltip.

 

3. Which CSS property makes a background fully transparent?

A background-color: rgba(0, 0, 0, 0);

B background-color: transparent;

C opacity: 0;

D A and B

D
Both options make the background transparent, but background-color: transparent; is the most direct way to define a transparent background, while rgba(0, 0, 0, 0) uses the RGBA color model with 0 opacity.
 
 

4. How do you add an HTML button that triggers a JavaScript action on click?

A <button onclick="alert('Hello!')">Click here</button>

B <button href="javascript:alert('Hello!')">Click here</button>

C <button action="alert('Hello!')">Click here</button>

D <button href="javascript:void(0)">Click here</button>

A
The onclick attribute lets you run a JavaScript function when the button is clicked, in this case, showing an alert. Example:
 

5. What is the purpose of the <details> tag in HTML?

A Display a dropdown menu of links

B Create a modal dialog box

C Create an accordion or collapsible section

D Add extra details to a list

C
The <details> tag creates a collapsible section in a document, which the user can expand or hide by clicking on the <summary> tag. See a full example.
 

6. Which HTML tag allows you to create an internal link to another section of the same page?

A <a href="#section1">Go to section 1</a>

B <button href="#section1">Go to section 1</button>

C <link href="#section1">Go to section 1</link>

D <a link="#section1">Go to section 1</a>

A
The href="#section1" attribute creates an internal link that navigates the user to the page element with the ID “section1”.
 
 

7. Which HTML tag allows you to include vector graphics directly in a web page?

A <image>

B <canvas>

C <svg>

D <vector>

C
The <svg> tag allows you to draw vector graphics directly in HTML using SVG (Scalable Vector Graphics). See a full example.
 

8. How do you add a mailto link with a pre-filled subject and body?

A <a href="mailto:[email protected]?subject=Hi&body=How are you?">Send email</a>

B <a href="mailto:[email protected]&subject=Hi&body=How are you?">Send email</a>

C <a href="mailto:[email protected]?body=How are you?">Send email</a>

D <a href="mailto:[email protected]?body=Hi">Send email</a>

A
The mailto link can include a subject and body using parameters in the URL (subject and body). Example: Send email
 

9. How do you create a link that selects text on an HTML page?

A <a href="#" onclick="document.body.selectAll();">Select all text</a>

B <a href="#" onclick="window.selectAllText();">Select all text</a>

C <a href="javascript:void(0);" onclick="document.body.selectText();">Select all text</a>

D <a href="javascript:void(0);" onclick="window.getSelection().selectAllChildren(document.body);">Select all text</a>

D
The getSelection().selectAllChildren() method selects all the text content of a page when clicked. Example: Select all text
 
 

10. How do you add a video with custom controls (e.g., no progress bar) in HTML?

A <video src="video.mp4" controls></video>

B <video src="video.mp4" controlsList="nodownload noprogressbar"></video>

C <video src="video.mp4" autoplay controls></video>

D <video src="video.mp4" controlsList="nodownload"></video>

B
The controlsList attribute allows you to customize the video controls, in this case removing the progress bar and the download option.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *