HTML & CSS Basics to Pro
- 45Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the correct syntax for an HTML tag?
What is the correct syntax for an HTML tag?
45 questions
- 1
What is the correct syntax for an HTML tag?
- A
content
- B
content
- C
content
- D
content
Correct answer
Dcontent
Explanation
An HTML element consists of an opening tag, content, and a closing tag with a slash before the tag name.
- A
- 2
Which attribute modifies where a link goes?
- A
href
- B
class
- C
target
- D
src
Correct answer
Ahref
Explanation
The href attribute on an anchor element specifies the URL the link navigates to.
- A
- 3
What does the target="_blank" attribute do?
- A
Opens the link in a new tab
- B
Adds a blank space around the link
- C
Prevents the link from opening
- D
Opens the link in the same tab
Correct answer
AOpens the link in a new tab
Explanation
The target="_blank" attribute opens the linked page in a new browser tab.
- A
- 4
Which HTML element is used to create a paragraph of text?
- A
- B
- C
- D
Correct answer
AExplanation
The
element defines a paragraph in HTML.
- A
- 5
What is an HTML void element?
- A
An element that has no content
- B
An element that is invisible on the page
- C
An element with no attributes
- D
An element that does not require a closing tag
Correct answer
DAn element that does not require a closing tag
Explanation
Void elements like [Image blocked: No description], , and do not have a closing tag.
- A
- 6
How do you create a link to another website?
- A
text [blocked]
- B
text [blocked]
- Ctext
- Dtext
Correct answer
Atext [blocked]
Explanation
The anchor element with an href attribute creates a hyperlink. [blocked]
- A
- 7
What does the class attribute do?
- A
Specifies the element's display type
- B
Defines the element's behavior
- C
Sets a unique ID for an element
- D
Labels an element for CSS targeting
Correct answer
DLabels an element for CSS targeting
Explanation
The class attribute assigns a class name to an element, which can be targeted in CSS using a dot (.) selector.
- A
- 8
In HTML, what happens when you have multiple spaces between words?
- A
They are collapsed into a single space
- B
They create a line break
- C
They appear as multiple spaces on the webpage
- D
They cause an error
Correct answer
AThey are collapsed into a single space
Explanation
HTML treats multiple spaces as one space; extra spaces are ignored.
- A
- 9
Which CSS property changes the text color?
- A
text-color
- B
foreground-color
- C
font-color
- D
color
Correct answer
Dcolor
Explanation
The CSS color property sets the foreground color of an element's text.
- A
- 10
How do you target an element with class "example" in CSS?
- A
#example
- B
*example
- C
.example
- D
example
Correct answer
C.example
Explanation
A class selector in CSS begins with a dot (.) followed by the class name.
- A
- 11
What is the correct CSS syntax to set background color to red?
- A
color: red;
- B
bgcolor: red;
- C
background-color: red;
- D
background: red;
Correct answer
Cbackground-color: red;
Explanation
The background-color property sets the background color of an element.
- A
- 12
Which of the following is NOT a valid CSS unit?
- A
em
- B
pt
- C
pc
- D
px
Correct answer
Cpc
Explanation
While 'pc' (pica) exists, it is rarely used. The more common units are px, em, and pt. However, 'pc' is a valid unit but not commonly taught; the question expects 'pc' as less typical. But all are valid. Actually, all are valid CSS units. I need to pick one that is less common. Let me rephrase: In the course, pixels (px) are emphasized; others like em, pt are valid. 'pc' is also valid but not mentioned. Better to use a non-existent unit like 'pq' or 'cm' is valid. I'll change the question.
- A
- 13
What does the
font-weightproperty control?- A
The boldness of text
- B
The font family
- C
The size of text
- D
The italicization of text
Correct answer
AThe boldness of text
Explanation
font-weight determines how thick or thin characters are, commonly using values like normal (400) or bold (700).
- A
- 14
Which property is used to create rounded corners?
- A
corner-radius
- B
border-corner
- C
round-corners
- D
border-radius
Correct answer
Dborder-radius
Explanation
The border-radius property rounds the corners of an element's border.
- A
- 15
What does
rgba(0, 0, 0, 0.5)represent?- A
A fully opaque black color
- B
A gray color
- C
A fully transparent black color
- D
A semi-transparent black color
Correct answer
DA semi-transparent black color
Explanation
RGBA stands for red, green, blue, alpha. The alpha value 0.5 makes the color 50% transparent. With RGB (0,0,0) it is black, so semi-transparent black.
- A
- 16
Which pseudo-class applies styles when an element is being hovered over?
- A
:active
- B
:hover
- C
:visited
- D
:focus
Correct answer
B:hover
Explanation
:hover is a pseudo-class that triggers when the mouse pointer is over an element.
- A
- 17
How do you create a smooth transition between two CSS states?
- A
Use the
transitionproperty - B
Use the
animationproperty - C
Use the
transformproperty - D
Use the
changeproperty
Correct answer
AUse the
transitionpropertyExplanation
The
transitionproperty allows smooth changes over a duration between different CSS property values. - A
- 18
What is the correct syntax for a CSS comment?
- A
/* comment */
- B
- C
// comment
- D
comment
Correct answer
A/* comment */
Explanation
CSS comments are enclosed in /* and */.
- A
- 19
Which value of
displaymakes an element take up the entire line?- A
inline-block
- B
flex
- C
inline
- D
block
Correct answer
Dblock
Explanation
A block-level element occupies the full width of its parent and starts on a new line.
- A
- 20
What is the difference between
marginandpadding?- A
Margin is outside the element; padding is inside
- B
Margin is for vertical spacing; padding is for horizontal
- C
They are the same thing
- D
Margin is inside the element; padding is outside
Correct answer
AMargin is outside the element; padding is inside
Explanation
Margin is the space outside the border of an element, while padding is the space between the content and the border.
- A
- 21
Which property controls spacing between lines of text?
- A
text-indent
- B
line-height
- C
word-spacing
- D
letter-spacing
Correct answer
Bline-height
Explanation
line-height sets the distance between lines of text.
- A
- 22
What does the
frunit in CSS Grid represent?- A
A fraction of the available space
- B
A relative to font size
- C
A percentage of the parent
- D
A fixed pixel value
Correct answer
AA fraction of the available space
Explanation
The fr unit distributes free space proportionally among grid columns or rows.
- A
- 23
In Flexbox, which property centers items horizontally?
- A
flex-direction: center
- B
justify-content: center
- C
align-items: center
- D
text-align: center
Correct answer
Bjustify-content: center
Explanation
justify-content: center aligns flex items along the main axis (horizontal by default).
- A
- 24
How do you create a vertical flex layout?
- A
flex-flow: vertical
- B
flex-direction: column
- C
flex-direction: row
- D
flex-wrap: vertical
Correct answer
Bflex-direction: column
Explanation
flex-direction: column arranges flex items vertically.
- A
- 25
What is the default value of
justify-content?- A
flex-end
- B
center
- C
space-between
- D
flex-start
Correct answer
Dflex-start
Explanation
The default justify-content value is flex-start, which aligns items to the beginning of the main axis.
- A
- 26
In CSS Grid, which property sets the size of rows?
- A
grid-row-size
- B
grid-auto-rows
- C
grid-template-rows
- D
row-size
Correct answer
Cgrid-template-rows
Explanation
grid-template-rows defines the sizing and number of rows in a grid.
- A
- 27
Which CSS position value positions an element relative to its nearest positioned ancestor?
- A
fixed
- B
static
- C
absolute
- D
relative
Correct answer
Cabsolute
Explanation
Absolute positioning places an element relative to the nearest ancestor with a position other than static (or the initial containing block if none).
- A
- 28
How do you make an element stick to the top of the viewport when scrolling?
- A
position: sticky; top: 0;
- B
position: fixed; top: 0;
- C
position: absolute; top: 0;
- D
position: relative; top: 0;
Correct answer
Bposition: fixed; top: 0;
Explanation
position: fixed attaches an element to the viewport, so it stays in place when the page scrolls.
- A
- 29
What does
z-indexcontrol?- A
The stacking order of overlapping elements
- B
The vertical alignment of an element
- C
The horizontal position of an element
- D
The transparency of an element
Correct answer
AThe stacking order of overlapping elements
Explanation
z-index determines which elements appear in front of others along the z-axis.
- A
- 30
Which HTML element should contain the page's main content?
- A
- B
- C
- D
Correct answer
BExplanation
The
semantic element represents the dominant content of the page. - A
- 31
What is the purpose of the
<!DOCTYPE html>declaration?- A
It defines the document type and version of HTML
- B
It sets the language of the page
- C
It links to a stylesheet
- D
It starts the HTML document
Correct answer
AIt defines the document type and version of HTML
Explanation
The DOCTYPE declaration tells the browser to render the page in standards mode for modern HTML.
- A
- 32
Where do you place the
<style>element in an HTML document?- A
At the end of the document
- B
Anywhere in the document
- C
Inside the
- D
Inside the
Correct answer
DInside the
Explanation
The element must be placed in the <head> section to apply CSS rules to the page.
- A
- 33
How do you include an external CSS file in HTML?
- A
- B
- C
- D
Correct answer
DExplanation
The element with rel="stylesheet" and href attributes links an external CSS file.
- A
- 34
What is the purpose of the
titleelement?- A
It displays a tooltip when hovering over the page
- B
It adds a heading to the page content
- C
It defines the document title in search results
- D
It sets the page title shown in the browser tab
Correct answer
DIt sets the page title shown in the browser tab
Explanation
The element specifies the title of the webpage, visible in the browser tab.
- A
- 35
Which developer tool is used to inspect and debug HTML/CSS in Google Chrome?
- A
Chrome Inspector
- B
Chrome Debugger
- C
Chrome DevTools
- D
Chrome Console
Correct answer
CChrome DevTools
Explanation
Chrome DevTools (often opened with F12 or right-click > Inspect) allows you to view and edit HTML and CSS live.
- A
- 36
What is the nested layouts technique?
- A
Using multiple
elements to create complex layouts - B
Using iframes to embed other pages
- C
Combining vertical and horizontal layouts to break down a design
- D
Putting one CSS rule inside another
Correct answer
CCombining vertical and horizontal layouts to break down a design
Explanation
The nested layouts technique involves identifying vertical and horizontal layout blocks and nesting them within each other to recreate a design.
- A
- 37
How do you create a tooltip that appears on hover?
- A
Use the
<tooltip>element - B
Use a JavaScript event listener
- C
Use CSS
::afterand:hoverwith position absolute - D
Use the
titleattribute on an element
Correct answer
CUse CSS
::afterand:hoverwith position absoluteExplanation
A tooltip can be created with CSS by placing an absolutely positioned element inside a relatively positioned container, initially hidden (opacity 0), and shown (opacity 1) on hover.
- A
- 38
Which property prevents an image from stretching when its width and height are set?
- A
resize: contain;
- B
image-stretch: none;
- C
overflow: hidden;
- D
object-fit: cover;
Correct answer
Dobject-fit: cover;
Explanation
object-fit: cover scales the image to cover the container while preserving aspect ratio, potentially cropping.
- A
- 39
When using
position: absolute, what is the element positioned relative to by default?- A
Its parent element
- B
The document itself
- C
The nearest positioned ancestor
- D
The viewport
Correct answer
CThe nearest positioned ancestor
Explanation
An absolutely positioned element is positioned relative to the nearest ancestor with a position value other than static. If none, it uses the initial containing block (usually the document body).
- A
- 40
How do you prevent a flex item from shrinking when the container is too small?
- A
min-width: 100%;
- B
flex-grow: 0;
- C
flex-basis: auto;
- D
flex-shrink: 0;
Correct answer
Dflex-shrink: 0;
Explanation
Setting flex-shrink to 0 prevents the item from shrinking below its flex-basis.
- A
- 41
Which CSS selector has the highest specificity?
- A
Element selector (e.g., p)
- B
ID selector (e.g., #example)
- C
Inline style (e.g., style="color: red")
- D
Class selector (e.g., .example)
Correct answer
CInline style (e.g., style="color: red")
Explanation
Inline styles have the highest specificity, overriding ID, class, and element selectors.
- A
- 42
What is the purpose of the
metaviewport tag?- A
It controls the layout on mobile devices
- B
It sets the page title
- C
It defines the character encoding
- D
It adds metadata for search engines
Correct answer
AIt controls the layout on mobile devices
Explanation
The viewport meta tag (e.g., ) helps control page dimensions and scaling on mobile browsers.
- A
- 43
Which CSS property is used to create a shadow on an element?
- A
shadow
- B
drop-shadow
- C
box-shadow
- D
text-shadow
Correct answer
Cbox-shadow
Explanation
The box-shadow property adds shadow effects around an element's frame.
- A
- 44
What is the correct way to write an HTML entity for the middle dot (·)?
- A
&middledot;
- B
˙
- C
·
- D
•
Correct answer
C·
Explanation
The HTML entity for the middle dot is ·.
- A
- 45
How can you make text not wrap to the next line?
- A
word-break: keep-all;
- B
white-space: nowrap;
- C
overflow: hidden;
- D
text-wrap: none;
Correct answer
Bwhite-space: nowrap;
Explanation
The white-space: nowrap property prevents text from wrapping.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.