CodeHS Web Development Accreditations 2 — Questions and Answers
Question 1: In CSS, which property controls the space between an element's border and its surrounding elements?
- padding
- margin (Correct answer)
- border-spacing
- gap
Correct answer: margin
The margin property sets the space outside an element's border, pushing it away from neighboring elements.
Question 2: Which HTML attribute makes a form input field required before submission?
- mandatory
- required (Correct answer)
- validate
- nonempty
Correct answer: required
The 'required' attribute prevents form submission if the field is empty and triggers a browser validation message.
Question 3: What does the CSS 'z-index' property control?
- Element transparency
- Stacking order of overlapping elements (Correct answer)
- Horizontal scroll position
- Font size scaling
Correct answer: Stacking order of overlapping elements
z-index determines which element appears on top when elements overlap, with higher values appearing in front.
Question 4: Which JavaScript method removes the last element from an array and returns it?
- shift()
- splice()
- pop() (Correct answer)
- slice()
Correct answer: pop()
Array.pop() removes and returns the last element, mutating the original array.
Question 5: In HTML, which tag is used to link an external CSS stylesheet?
- <style>
- <script>
- <link> (Correct answer)
- <css>
Correct answer: <link>
The <link rel='stylesheet' href='...'> tag in the <head> section connects an external CSS file to the HTML document.
Question 6: What is the purpose of the 'alt' attribute on an <img> tag?
- Sets image dimensions
- Provides alternative text for accessibility and when image fails to load (Correct answer)
- Links to a higher-resolution version
- Adds a tooltip on hover
Correct answer: Provides alternative text for accessibility and when image fails to load
The alt attribute supplies descriptive text for screen readers and displays when an image cannot be rendered.
Question 7: Which CSS display value makes an element behave like a block but allows other elements beside it?
- block
- inline
- inline-block (Correct answer)
- flex
Correct answer: inline-block
inline-block lets you set width/height like a block element while still flowing inline with surrounding content.
In CSS, which property controls the space between an element's border and its surrounding elements?