Website with HTML & CSS
- 25Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the purpose of setting margin: 0; padding: 0; in CSS before styling other elements?
25 questions
- 1
What is the purpose of setting
margin: 0; padding: 0;in CSS before styling other elements?Model answer
To remove default browser margins and padding, ensuring a consistent baseline for custom styling.
Explanation
Browsers apply default margins and paddings on elements like
body; resetting them prevents unexpected spacing. - 2
How do you link an external CSS file named
style.cssto an HTML document?Model answer
Use
<link rel="stylesheet" href="style.css">inside the<head>section.Explanation
The
<link>tag withrel="stylesheet"andhrefpointing to the CSS file is the standard method. - 3
What CSS property and value are used to create a linear gradient background?
Model answer
background: linear-gradient(direction, color-stop1, color-stop2, ...);Explanation
The
linear-gradient()function allows smooth color transitions; direction can beto top,to bottom,to left,to right, or an angle. - 4
How do you make a background image 50% dimmer using a linear gradient?
Model answer
Use
background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url('image.jpg');Explanation
A semi-transparent black overlay (
rgba(0,0,0,0.5)) layered on top of the background image reduces brightness. - 5
What CSS properties are needed to set a background image to cover the entire element and center it?
Model answer
background-size: cover; background-position: center;Explanation
coverscales the image to cover the element while maintaining aspect ratio;centerpositions it centrally. - 6
What does
height: 100vh;achieve in CSS?Model answer
It sets the element's height to 100% of the viewport height.
Explanation
vhstands for viewport height;100vhequals the full visible height of the browser window. - 7
How do you center a block element horizontally using
margin?Model answer
Set
margin: auto;on the element with a defined width.Explanation
When an element has a width less than its container,
margin: autodistributes equal space left and right. - 8
What does
display: flex;do to a container?Model answer
It enables a flexbox layout, allowing flexible alignment and distribution of child elements.
Explanation
Flexbox provides powerful alignment properties like
justify-contentandalign-items. - 9
How do you center items both horizontally and vertically using flexbox?
Model answer
Use
display: flex; justify-content: center; align-items: center;Explanation
justify-content: centercenters along the main axis;align-items: centercenters along the cross axis. - 10
What CSS property removes the default bullet points from an unordered list?
Model answer
list-style: none;Explanation
Setting
list-styletononeremoves markers (bullets, numbers) from list items. - 11
How do you change the color of an anchor link and remove its underline?
Model answer
Use
color: desired-color; text-decoration: none;Explanation
text-decoration: noneremoves the underline;colorsets the text color. - 12
What CSS property and value create a smooth color change when hovering over an element?
Model answer
transition: property duration timing-function;e.g.,transition: 0.4s ease-in-out;Explanation
The
transitionproperty animates changes over a specified duration with an easing function. - 13
Write CSS to change an element's background color to orange on hover.
Model answer
element:hover { background: orange; }Explanation
The
:hoverpseudo-class applies styles when the mouse pointer is over the element. - 14
How do you create a search input with a rounded left border and a button with a rounded right border?
Model answer
Set
border-top-left-radiusandborder-bottom-left-radiuson the input, andborder-top-right-radiusandborder-bottom-right-radiuson the button.Explanation
Border-radius properties control individual corners; combining them creates a seamless joined search bar.
- 15
What does
background: transparent;do on an input field?Model answer
It makes the input's background transparent, allowing the parent's background to show through.
Explanation
transparentsets the background to fully see-through; often used with a colored border for a modern look. - 16
How do you remove the default focus outline from an input field?
Model answer
Use
input:focus { outline: none; }Explanation
Removing the outline can affect accessibility; alternative focus indicators should be provided.
- 17
What CSS property controls the space between letters?
Model answer
letter-spacingExplanation
letter-spacingincreases or decreases the space between characters in text. - 18
How do you position an element absolutely relative to its nearest positioned ancestor?
Model answer
Set
position: absolute;on the element andposition: relative;on the ancestor.Explanation
Absolute positioning removes the element from normal flow and places it relative to the closest positioned (non-static) ancestor.
- 19
What does
cursor: pointer;do?Model answer
It changes the mouse cursor to a hand icon, indicating the element is clickable.
Explanation
Commonly used on buttons and links to improve user experience.
- 20
How do you change the color of placeholder text in an input field?
Model answer
Use
::placeholderpseudo-element withcolorproperty, e.g.,input::placeholder { color: white; }Explanation
The
::placeholderselector targets placeholder text specifically. - 21
What HTML elements are used to create a navigation menu with a list of links?
Model answer
<nav>or<div>,<ul>,<li>, and<a>tags.Explanation
A typical navigation menu uses an unordered list (
<ul>) with list items (<li>) containing anchor links (<a>). - 22
How do you create a login form with email and password fields?
Model answer
Use
<form>containing<input type="email">and<input type="password">, plus a submit button.Explanation
The
type="email"validates email format;type="password"masks input for security. - 23
What attribute is used in an anchor tag to link to an external page?
Model answer
The
hrefattribute.Explanation
hrefspecifies the URL of the page the link goes to. - 24
How do you add social media icons from an icon library like Font Awesome?
Model answer
Use
<i class="fab fa-facebook-f"></i>inside an anchor tag, with the appropriate class names.Explanation
Font Awesome icons are applied via classes;
fabfor brand icons,fa-followed by the icon name. - 25
What is the purpose of the
<span>tag in HTML?Model answer
To group inline elements for styling without adding new lines.
Explanation
<span>is an inline container used to apply CSS or JavaScript to a portion of text.

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