HTML & CSS Basics to Pro
- 55Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What does HTML stand for?
55 questions
- 1
What does HTML stand for?
Model answer
Hypertext Markup Language.
Explanation
HTML is a markup language used to create the structure of web pages.
- 2
What are the two parts of a typical HTML element?
Model answer
An opening tag and a closing tag.
Explanation
Most HTML elements consist of an opening tag like and a closing tag like , with content in between.
- 3
How do you create a hyperlink to another website in HTML?
Model answer
Use an anchor element with the href attribute set to the URL. [blocked]
Explanation
The anchor element creates a link, and the href attribute specifies the destination URL. [blocked]
- 4
What attribute makes a link open in a new tab?
Model answer
The target attribute set to "_blank".
Explanation
Adding target="_blank" to an anchor element causes the link to open in a new browser tab.
- 5
What happens to multiple consecutive spaces in HTML code when rendered in a browser?
Model answer
They are collapsed into a single space.
Explanation
HTML treats multiple spaces as one; extra spaces are ignored to allow flexible formatting.
- 6
What is a void element? Give an example.
Model answer
A void element is an HTML element that does not require a closing tag, such as [Image blocked: No description] or .
Explanation
Void elements are self-closing; they cannot have content between tags. Examples include [Image blocked: No description], , and
. - 7
What is the purpose of the placeholder attribute on an input element?
Model answer
It displays a short hint inside the input field before the user enters a value.
Explanation
The placeholder attribute provides a prompt to the user, which disappears when typing begins.
- 8
How do you load an image onto a webpage using HTML?
Model answer
Use the [Image blocked: No description] element with the src attribute specifying the image file path.
Explanation
The [Image blocked: No description] element is a void element; the src attribute tells the browser where to find the image file.
- 9
Write the CSS syntax to style all button elements.
Model answer
button { property: value; }
Explanation
A CSS rule consists of a selector (here, 'button') followed by curly braces containing property-value pairs.
- 10
How do you target an element with a specific class in CSS?
Model answer
Use a dot followed by the class name, e.g., .className.
Explanation
The class selector starts with a period and matches any element that has the given class attribute.
- 11
What is the difference between RGB and RGBA color values?
Model answer
RGBA includes an alpha channel for opacity (transparency).
Explanation
RGB specifies red, green, blue values (0-255 each). RGBA adds a fourth value (a) from 0 (transparent) to 1 (opaque).
- 12
Which CSS property changes the text color of an element?
Model answer
The color property.
Explanation
The color property sets the foreground color of text content.
- 13
Which CSS property sets the background color of an element?
Model answer
The background-color property.
Explanation
background-color fills the element's background with a specified color.
- 14
How do you change the font used on an element in CSS?
Model answer
Use the font-family property with the desired font name.
Explanation
font-family specifies a prioritized list of font names; the browser uses the first available one.
- 15
What does the border-radius property do?
Model answer
It rounds the corners of an element's border.
Explanation
border-radius takes a length value; higher values produce more rounded corners. Setting it to half the element's height/width creates a circle.
- 16
How can you make an element completely transparent using CSS?
Model answer
Set its opacity property to 0.
Explanation
Opacity ranges from 0 (fully transparent) to 1 (fully opaque).
- 17
What is a pseudo-class in CSS? Give an example.
Model answer
A pseudo-class defines a special state of an element, such as :hover for when the mouse hovers over it.
Explanation
Pseudo-classes are appended to selectors with a colon, e.g., button:hover, and apply styles only in that state.
- 18
List the four parts of the CSS box model in order from outside to inside.
Model answer
Margin, border, padding, content.
Explanation
The box model describes the space around an element: margin is outside, then border, then padding, then the actual content.
- 19
What is the difference between margin and padding?
Model answer
Margin is space outside the element's border; padding is space inside the border, between the border and content.
Explanation
Margin creates separation between elements, while padding adds space within the element around the content.
- 20
How can you make two block-level elements appear side by side?
Model answer
Set their display property to inline-block, or use a grid/flexbox layout.
Explanation
Block elements normally take full width. Changing display to inline-block makes them flow horizontally while respecting width/height.
- 21
What is the default display value of a
element?Model answer
Block.
Explanation
By default,
is a block-level element, meaning it occupies the entire width of its parent and starts on a new line. - 22
Which CSS property centers text horizontally inside a block element?
Model answer
text-align: center;
Explanation
The text-align property can be set to left, right, center, or justify to control horizontal alignment of inline content.
- 23
What CSS property controls the spacing between lines of text?
Model answer
The line-height property.
Explanation
line-height sets the vertical distance between lines of text, often specified in pixels or unitless multipliers.
- 24
How do you create a CSS grid layout?
Model answer
Set display: grid on the container and define columns with grid-template-columns.
Explanation
display: grid enables grid formatting; grid-template-columns specifies the width and number of columns.
- 25
What does the fr unit mean in CSS Grid?
Model answer
It represents a fraction of the available free space in the grid container.
Explanation
The fr unit distributes remaining space proportionally among columns or rows. For example, 1fr 1fr creates two equal columns.
- 26
How do you add space between grid columns?
Model answer
Use the column-gap property.
Explanation
column-gap sets the gutter width between columns in a grid or flex container.
- 27
How do you create a flex container?
Model answer
Set display: flex on the parent element.
Explanation
display: flex turns the element into a flex container, and its direct children become flex items.
- 28
What is the default flex-direction value?
Model answer
Row.
Explanation
flex-direction: row arranges flex items horizontally from left to right (in left-to-right languages).
- 29
How do you vertically center items inside a flex container?
Model answer
Set align-items: center on the container.
Explanation
align-items controls alignment along the cross axis (perpendicular to flex-direction). For a row, cross axis is vertical.
- 30
What CSS property makes a flex item expand to fill remaining space?
Model answer
flex: 1;
Explanation
The flex shorthand property (or flex-grow) can be set to 1 to allow the item to grow and take up available space.
- 31
How do you prevent a flex item from shrinking when the container is resized?
Model answer
Set flex-shrink: 0 on the item.
Explanation
flex-shrink controls whether an item can shrink. A value of 0 prevents shrinking.
- 32
What is the difference between justify-content and align-items in flexbox?
Model answer
justify-content aligns items along the main axis; align-items aligns them along the cross axis.
Explanation
The main axis is defined by flex-direction (row or column). justify-content distributes space along that axis; align-items aligns perpendicularly.
- 33
Name the four values of the CSS position property.
Model answer
static, relative, absolute, fixed.
Explanation
position: static is default; relative positions relative to its normal position; absolute positions relative to nearest positioned ancestor; fixed positions relative to the viewport.
- 34
How does position: fixed behave differently from position: absolute?
Model answer
Fixed positions the element relative to the viewport, so it stays in place during scrolling. Absolute positions relative to the nearest positioned ancestor (or the initial containing block) and scrolls with the page.
Explanation
Elements with position: fixed are removed from normal flow and do not move when the page scrolls. Absolute elements scroll with the page unless they are inside a positioned ancestor.
- 35
How do you position an element absolutely inside a relative container?
Model answer
Set the container to position: relative, and the child to position: absolute, then use top, right, bottom, or left.
Explanation
With the parent as a positioning context, the absolute child's coordinates are measured from the parent's edges.
- 36
What is the purpose of the z-index property?
Model answer
It controls the stacking order of positioned elements (those with a position value other than static).
Explanation
A higher z-index value places the element in front of elements with lower values. Default is 0.
- 37
Describe the technique to create a tooltip that appears on hover.
Model answer
Place the tooltip element inside a relative parent. Set the tooltip to position: absolute and opacity: 0 by default. On hover, change opacity to 1, often with a transition for smoothness.
Explanation
The absolute positioning places the tooltip relative to its parent. The opacity change combined with a transition creates a fade-in effect on hover.
- 38
What does the pointer-events: none CSS property do?
Model answer
It prevents the element from becoming the target of mouse events; clicks and hovers pass through it.
Explanation
Setting pointer-events: none makes the element 'transparent' to pointer interactions, useful for tooltips that should not interfere with underlying elements.
- 39
What is a media query used for in CSS?
Model answer
To apply different styles based on the screen size or device characteristics.
Explanation
Media queries allow responsive design by conditionally applying CSS rules when certain conditions (like max-width) are met.
- 40
Write a media query that applies styles only on screens smaller than 600 pixels wide.
Model answer
@media (max-width: 600px) { /* CSS rules here */ }
Explanation
The @media rule with max-width: 600px activates the enclosed styles when the viewport width is 600px or less.
- 41
What is CSS inheritance? Name one property that is typically inherited.
Model answer
Inheritance is the mechanism by which certain CSS property values are passed from parent elements to their children. An example is the color property.
Explanation
Text-related properties like font-family, color, and line-height are inherited by default, while layout properties like margin are not.
- 42
What is CSS specificity?
Model answer
It is a set of rules that determines which CSS rule takes precedence when multiple rules apply to the same element.
Explanation
Specificity is calculated based on selector types: inline styles > IDs > classes/pseudo-classes > element selectors. Higher specificity overrides lower.
- 43
How do you write a comment in CSS?
Model answer
Enclose the comment between /* and */.
Explanation
CSS comments are ignored by browsers and used for documentation. Example: /* This is a comment */
- 44
How do you write a comment in HTML?
Model answer
Enclose the comment between .
Explanation
HTML comments are not displayed on the page. Example:
- 45
What is a semantic HTML element? Give an example.
Model answer
A semantic element clearly describes its meaning to both the browser and the developer, such as
, , , or. Explanation
Semantic elements provide structure and improve accessibility and SEO by conveying the role of the content.
- 46
What is the shorthand CSS property for setting all four margins at once? How do you use it with two values?
Model answer
The margin shorthand. Two values: margin: vertical horizontal; sets top and bottom to the first value, left and right to the second.
Explanation
The margin property can take 1, 2, 3, or 4 values. Two values apply to vertical (top/bottom) and horizontal (left/right) directions respectively.
- 47
What does the transition property do in CSS?
Model answer
It enables smooth animation between style changes over a specified duration.
Explanation
The transition property specifies which property to animate (e.g., opacity) and the duration (e.g., 0.15s). The default is instant change.
- 48
How do you create a box shadow in CSS? Write the syntax with its four values.
Model answer
box-shadow: horizontal-offset vertical-offset blur-radius color;
Explanation
The horizontal and vertical offsets determine the shadow's position, blur-radius softens the edge, and color sets the shadow's color.
- 49
What is the difference between the and elements? (based on the course: strong is a semantic element for importance, but course only mentions strong as bold text. Since content only mentions strong as bold, we'll stick to that.)
Model answer
The element makes text bold by default, but it also conveys strong importance semantically. (The course treats it as a text element for bold.)
Explanation
In the course, is used as an inline element to bold a portion of text.
- 50
What is the purpose of the element?
Model answer
It is used to embed CSS code directly within an HTML file.
Explanation
The element is placed in the <head> and contains CSS rules that apply to the document.
- 51
How do you link an external CSS file to an HTML document?
Model answer
Use the element with rel="stylesheet" and href pointing to the CSS file.
Explanation
The element is placed in the and connects the HTML to an external stylesheet.
- 52
What is the correct HTML structure for a webpage? Write the minimal required tags.
Model answer
Explanation
Every HTML document should start with , followed by containing and .
- 53
What is the purpose of the element?
Model answer
It specifies the title of the webpage, which appears in the browser tab.
Explanation
The element is placed inside <head> and provides the page name for the tab and search results.
- 54
How do you create a text input field in HTML?
Model answer
Use the element with type="text".
Explanation
The input element is a void element; the type attribute determines its behavior. type="text" creates a single-line text box.
- 55
What is the default display value of a element?
Model answer
Inline.
Explanation
The element is an inline container, meaning it does not start a new line and only takes as much width as necessary.

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