HTML/CSS MCQ

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

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 create a page background with an image that repeats across the entire page?

A background: url('pattern.png') repeat;

B background-repeat: no-repeat; background-image: url('pattern.png');

C background: url('pattern.png') fixed;

D background-image: repeat('pattern.png');

A
The background-repeat: repeat; property allows the image to repeat across the entire surface of the element (in this case, the page).
 

2. How do you create a link that downloads a file when clicked?

A <a href="file.pdf" download>Download File</a>

B <a href="file.pdf" target="_blank" download>Download File</a>

C <a href="file.pdf" target="_self" download>Download File</a>

D <a href="file.pdf" rel="download">Download File</a>

A
The download attribute in an <a> tag forces the linked file to be downloaded.
 

3. How can you improve the accessibility of a button with ARIA in HTML?

A <button aria-label="Send message">Send</button>

B <button aria-hidden="true">Send</button>

C <button aria-live="polite">Send</button>

D <button aria-label="Submit">Submit</button>

A
The aria-label attribute provides an accessible description of the element, helping users understand the button’s purpose.
 
 

4. Which CSS property allows you to create a horizontal scrolling effect for text?

A white-space: nowrap; overflow: scroll;

B overflow-x: scroll; white-space: nowrap;

C overflow-x: auto; white-space: normal;

D overflow: hidden; white-space: nowrap;

B
overflow-x: scroll adds a horizontal scrollbar, and white-space: nowrap; prevents the text from wrapping, forcing it to scroll horizontally. See a full example.
 

5. How do you create a link to download an image in HTML?

A <a href="image.jpg" download="image.jpg">Download</a>

B <a href="image.jpg" target="_blank" download>Download</a>

C <a href="image.jpg" download>Download</a>

D <a href="image.jpg" target="_self" download="image.jpg">Download</a>

A
The download attribute allows you to specify that the image should be downloaded when the link is clicked. You can also specify the filename after the download attribute.
 

6. How do you create a fixed background on the entire page that doesn’t scroll with the content?

A background-attachment: static;

B background-attachment: scroll;

C background-attachment: absolute;

D background-attachment: fixed;

D
The background-attachment: fixed; property keeps the background fixed and prevents it from scrolling with the page content.
 
 

7. How do you create a numbered list using letters in HTML?

A <ol type="a"><li>First item</li></ol>

B <ol type="A"><li>First item</li></ol>

C <ul type="A"><li>First item</li></ul>

D <ol type="alpha"><li>First item</li></ol>

A
The type="a" attribute in the <ol> tag creates a numbered list with lowercase letters (a, b, c, etc.). Use type="A" for uppercase letters. See a full example.
 

8. How do you create a text area that limits the number of characters in HTML?

A <textarea maxlength="100"></textarea>

B <input type="text" maxlength="100">

C <input type="text" limit="100">

D <textarea limit="100"></textarea>

A
The maxlength attribute is used to limit the number of characters a user can enter in a <textarea> field. Example:

<textarea maxlength="3"></textarea>

Result:
 

 

9. When is it better to use CSS Grid over Flexbox?

A Grid is better for one-dimensional layouts (horizontal or vertical).

B Flexbox is better for complex layouts with multiple rows and columns.

C Grid is more suitable for two-dimensional layouts like rows and columns.

D Flexbox should only be used for centering elements within a container.

C
CSS Grid is designed for two-dimensional layouts (rows and columns), whereas Flexbox is more appropriate for one-dimensional layouts (either horizontal or vertical). Grid provides more control for complex structures.
 
 

10. Which HTML attribute specifies the method used to submit a form?

A action

B submit

C enctype

D method

D
The method attribute defines the HTTP method used to submit the form data. Common values are GET and POST. Example:

<form action="/submit" method="GET">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email">
  <br>
  <input type="submit" value="Send">
</form>
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 *