Deck 13 - HTML/CSS/Responsive/DOM Basics (Reviewer Essentials) Flashcards

Semantic HTML, forms, responsive layout, CSS fundamentals, DOM/events, common browser quirks, and review-style verdict wording. (80 cards)

1
Q

Deck 13 - HTML/CSS/Responsive/DOM Basics (Reviewer Essentials) (objective)

A

Goal: review UI code like a senior: semantic HTML, forms, layout, responsive patterns, DOM/events, and common browser pitfalls.
You learn: what/why (under the hood), common mistakes, and review-grade wording.
Output style: PASS/PARTIAL/FAIL + 2-3 issues + fix approach.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Semantics: why choose <button> vs <div onClick>?</button>

A

button has built-in keyboard support, focus management, and correct ARIA role.
div onClick requires manual keyboard handlers, tabindex, and ARIA; often fails accessibility and behavior parity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Semantics: link vs button rule.

A

Use <a> for navigation (changes URL / goes to another resource).
Use <button> for actions (mutations, toggles, submitting forms).</button></a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Forms: why button type matters.

A

Inside a form, <button> defaults to type=’submit’.
Best practice: set type=’button’ for non-submit buttons to avoid accidental submissions.</button>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Forms: label association (best practice).

A

Every input needs an accessible name: <label> or wrapping label, or aria-label/aria-labelledby.
Why: screen readers and click targets; also improves usability.</label>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Forms: placeholder is not a label (why).

A

Placeholder disappears on input and is not a reliable accessible name.
It also has low contrast by default; use a proper label.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Forms: controlled vs uncontrolled basics.

A

Controlled inputs rerender on each change; easier validation.
Uncontrolled use defaultValue/ref and read on submit; can be faster for huge forms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Forms: autocomplete best practice.

A

Use autocomplete hints like email, name, current-password.
Why: improves UX and reduces errors; helps password managers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

HTML: headings hierarchy rule.

A

Use a logical heading order (h1 then h2, etc.)
Why: screen reader navigation, SEO, and structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

HTML: list semantics rule.

A

Use <ul>/<ol> for lists; not a series of <div> elements.
Why: semantics, accessibility, and consistent spacing behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Images: alt text rule.

A

Decorative images: alt=’’. Informative images: meaningful alt.
Why: screen readers; missing alt can be noisy or unhelpful.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Images: width/height attributes (why).

A

Providing intrinsic dimensions reduces layout shift.
Why: avoids CLS-like jank as images load.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

CSS: box model basics (under the hood).

A

Elements have content + padding + border + margin.
box-sizing: border-box makes width/height include padding/border, reducing layout surprises.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

CSS: specificity basics.

A

More specific selectors win; !important overrides most.
Best practice: avoid deep specificity wars; use consistent class-based styling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Layout: flex vs grid rule of thumb.

A

Flex: 1D layout (row OR column). Grid: 2D layout (rows and columns).
Pick based on whether you need alignment in both axes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Responsive: mobile-first principle.

A

Start with base styles for small screens, then add min-width breakpoints.
Why: fewer overrides; better defaults for narrow devices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Responsive: common breakpoints (practical).

A

No single standard, but common: 480, 768, 1024, 1280.
Best practice: use content-based breakpoints rather than device-based.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Responsive: avoid fixed widths (rule).

A

Prefer max-width, flex, grid, and fluid units.
Why: fixed widths break on small screens and cause overflow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Units: rem/em/vw/vh (quick).

A

rem: root font size; em: relative to parent; vw/vh: viewport.
Best practice: use rem for typography and spacing; use vw/vh carefully (mobile address bar quirks).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Overflow: why text truncation needs more than one rule.

A

Truncation requires overflow hidden + text-overflow ellipsis + white-space nowrap (single line).
For multi-line, use line-clamp patterns with fallbacks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

DOM: event bubbling vs capturing (why you care).

A

Events bubble from target up; capturing goes down.
Why: delegation and unexpected parent handlers firing; stopPropagation is sometimes needed (sparingly).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

DOM: default actions (example).

A

Links navigate; forms submit; space/enter activate buttons.
If you preventDefault, ensure you still provide expected behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

DOM: focus management basics.

A

Focusable elements (button, input, link) participate in tab order.
Avoid tabindex>0; use tabindex=0 only when you must make custom elements focusable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

DOM: why :focus-visible is preferred.

A

Shows focus ring for keyboard users without always showing it for mouse clicks.
Best practice: do not remove focus outlines; style them intentionally.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
DOM: scroll locking pitfalls.
Locking body scroll can cause layout shift and iOS issues. Best practice: account for scrollbar width; test mobile Safari.
26
DOM: passive event listeners (why).
Passive listeners cannot call preventDefault; improves scroll performance. Use for touch/wheel when you do not need to cancel scrolling.
27
DOM: resize observers vs window resize.
ResizeObserver tracks element size changes; window resize tracks viewport only. Use ResizeObserver for component layout measurement.
28
DOM: measuring layout causes reflow (why).
Reading layout (getBoundingClientRect) can force layout. Batch reads/writes and avoid in hot paths; use requestAnimationFrame if needed.
29
DOM: innerHTML risk (quick).
Setting innerHTML can introduce XSS if content is untrusted. Prefer textContent or safe rendering methods.
30
DOM: dataset and attributes.
data-* attributes are strings; parse as needed. Avoid relying on DOM attributes for security-critical decisions.
31
Browser: CSS sticky common pitfall.
position: sticky requires a scrolling container and proper top/bottom. Overflow hidden/auto on ancestor can break sticky behavior.
32
Browser: 100vh mobile quirk.
Mobile browser UI changes viewport height; 100vh can be too tall. Use dynamic viewport units (svh/lvh/dvh) or JS workaround if necessary.
33
Browser: image rendering and object-fit.
object-fit: cover preserves aspect while filling box. Why: avoid stretched images; good for avatars/thumbnails.
34
Browser: font loading and FOIT/FOUT (concept).
Fonts can load late causing flash of invisible/un-styled text. Best practice: use font-display: swap and limit font variants.
35
Browser: why heavy box-shadows are expensive.
Shadows can increase paint cost. Best practice: use sparingly and avoid animating expensive paint properties.
36
Performance: which CSS properties are cheap to animate.
Prefer transform and opacity. Avoid animating layout properties (top/left/width) which trigger layout/reflow.
37
Responsive images: srcset/sizes basics.
Let browser choose best image for device size/resolution. Why: faster loads and less bandwidth.
38
Accessibility: reduced motion preference.
Respect prefers-reduced-motion to reduce or disable animations. Why: prevents motion sickness; improves accessibility.
39
Accessibility: color contrast basics.
Low contrast hurts readability. Best practice: ensure sufficient contrast for text and interactive elements.
40
UI state: disabled vs aria-disabled.
disabled attribute prevents focus/click for form controls. aria-disabled is for non-native controls; must still prevent activation in JS.
41
Gotcha: clickable div without keyboard support. ```
Open
```
FAIL - Non-semantic interactive element. Use
42
Gotcha: button inside form submits unexpectedly. ```
```
FAIL - button defaults to submit in forms. Add type='button' for non-submit actions.
43
Gotcha: input missing label. ``` ```
FAIL - Placeholder is not a label. Add
44
Gotcha: fixed width causes overflow on mobile. ``` .card { width: 900px; } ```
FAIL - Breaks responsiveness. Use max-width: 100%; width: min(900px, 100%); or fluid layout.
45
Gotcha: using px for font sizes everywhere.
PARTIAL - px can be okay, but rem is more scalable for user settings. Prefer rem for typography and spacing.
46
Gotcha: missing box-sizing reset.
PARTIAL - Without border-box, padding/border can create unexpected overflow. Consider a global box-sizing: border-box reset.
47
Gotcha: truncation missing required rules. ``` .name { text-overflow: ellipsis; } ```
FAIL - Needs overflow hidden + white-space nowrap (single line). Add required properties or use line-clamp for multi-line.
48
Gotcha: 100vh on mobile. ``` .hero { height: 100vh; } ```
PARTIAL - Mobile viewport changes can cause jump. Prefer 100dvh/svh or other responsive approach.
49
Gotcha: removing focus outline. ``` button:focus { outline: none; } ```
FAIL - Accessibility regression. Keep focus ring; style with :focus-visible instead.
50
Gotcha: using tabindex=0 everywhere. ```
...
```
PARTIAL - Adds focus stops and can harm keyboard UX. Use native focusable elements when possible.
51
Gotcha: image missing alt. ``` ```
FAIL - Missing alt. Use alt='' if decorative, or meaningful alt if informative.
52
Gotcha: using h1 multiple times for styling.
PARTIAL - One h1 per page is a common convention; use semantic headings for structure and style with CSS instead.
53
Gotcha: list rendered as divs. ``` {items.map(x =>
{x}
)} ```
PARTIAL - Use
  • for list semantics unless there is a strong reason not to.
54
Gotcha: link used as button. ``` Delete ```
FAIL - Use
55
Gotcha: button used as link. ``` ```
56
FAIL - Invalid/buggy interaction. Avoid nested interactive elements; use a single correct element.
57
Gotcha: missing rel on target blank. ``` Open ```
PARTIAL - Add rel='noopener noreferrer' to prevent reverse tabnabbing.
58
Gotcha: excessive specificity. ``` body .app .page .card .title { ... } ```
PARTIAL - Hard to override and maintain. Prefer simple class selectors and a consistent layering strategy.
59
Gotcha: animating layout properties. ``` .box { transition: width 200ms; } ```
PARTIAL - Animating width triggers layout. Prefer transform-based animations when possible.
60
Gotcha: overflow hidden breaks sticky. ``` .container { overflow: hidden; } .header { position: sticky; top: 0; } ```
PARTIAL - Sticky may fail due to overflow on ancestor. Adjust container overflow/structure.
61
Gotcha: using role incorrectly. ```
Open
```
PARTIAL - If you use role=button, you still need tabIndex=0 and keyboard handlers. Prefer
62
Gotcha: missing aria-live for async errors (when appropriate).
PARTIAL - For dynamic error messages, consider role='alert' or aria-live so screen readers announce changes.
63
Gotcha: using vw for font sizes.
PARTIAL - vw-based fonts can get too small/large. Use clamp() with rem to keep within sensible bounds.
64
Gotcha: no responsive meta tag (site-level).
FAIL - Without mobile scaling is broken. Ensure it exists in HTML template.
65
Gotcha: inconsistent tap targets on mobile.
PARTIAL - Small tap targets reduce usability. Increase padding and hit area for interactive controls.
66
Checklist: HTML/CSS review top 10.
1) Semantics (button/link/heading/list) 2) Labels and accessible names 3) Focus styles (:focus-visible) 4) Form button types 5) Responsive layout (no fixed widths) 6) Text overflow/truncation 7) Images (alt, sizing) 8) Cheap animations (transform/opacity) 9) Mobile viewport quirks (vh) 10) Avoid nested interactive elements
67
Mini-drill: write a verdict. ```
Save
```
FAIL - Non-semantic interactive element. Use
68
Mini-drill: write a verdict. ```
```
FAIL - Defaults to submit. Add type='button' for Cancel, and keep submit explicit.
69
Mini-drill: write a verdict. ``` ```
FAIL - Missing label. Add or aria-label.
70
Mini-drill: fix approach for layout overflow.
Replace fixed widths with fluid constraints (max-width:100%, flex/grid). Ensure container allows wrapping and uses gap rather than hard-coded spacing.
71
Mini-drill: explain why focus outline removal is bad.
It removes keyboard navigation feedback and is an accessibility regression. Use :focus-visible to style focus rings rather than removing them.
72
Mini-drill: when to use aria-disabled.
When using a non-native element as a control. But you must still prevent activation in JS and manage focus/keyboard. Prefer native disabled whenever possible.
73
Mini-drill: one-liner on why semantic HTML matters.
Semantics provide built-in accessibility, keyboard behavior, and consistent interaction without custom JS.
74
Mini-drill: verdict on nested interactive elements. ``` ```
FAIL - Nested interactive controls are invalid and can break focus/click behavior. Use a single element with correct semantics.
75
Mini-drill: verdict on missing alt. ``` ```
FAIL - Missing alt. Use alt='' if decorative or meaningful alt if it conveys information.
76
Mini-drill: explain truncation recipe.
Single-line: overflow:hidden; text-overflow:ellipsis; white-space:nowrap. Multi-line: -webkit-line-clamp with display:-webkit-box and fallbacks.
77
Mini-drill: explain cheap vs expensive animations.
Transform/opacity are cheap (composite). Layout properties (width/top/left) trigger layout + paint and are more expensive.
78
Mini-drill: mobile vh fix (high level).
Prefer dvh/svh units (100dvh) for full-height sections or compute height with JS if needed. Test iOS Safari.
79
Mini-drill: reviewer wording for responsive bug.
FAIL - Fixed dimensions prevent the layout from adapting on small screens; switch to fluid sizing (max-width, flex/grid) and add breakpoints based on content.
80
Mini-drill: reviewer wording for missing label.
FAIL - Input lacks an accessible name. Add a visible label linked via htmlFor/id (preferred) or aria-label if a visible label is not possible.