When something breaks, this is your one-stop page. Start with the workflow
to identify the type of problem, then jump to the relevant section for
specific fixes.
Quick Check
What is broken?
→ structure?
→ spacing?
→ alignment?
→ image?
→ responsive layout?
Where is it broken?
→ one section?
→ whole page?
When is it broken?
→ desktop?
→ tablet?
→ mobile?
Check the parent container first
Check direction before alignment
Check container size before blaming the content
Debugging Workflow
1. Identify the problem
2. Inspect the element
3. Check the parent
4. Check the box model
5. Check width / height
6. Check layout method
7. Check breakpoint
8. Re-test
Do not guess randomly
Change one thing
Observe it
Then decide the next move
Step by Step
Step 1: Identify the type of problem
Layout problem: check the container first
Spacing problem: check the element's own margin and padding
Size problem: check the element size or the wrapper limiting it
Text problem: check text alignment before reaching for flex
Step 2: Check DevTools
DevTools shows what the browser is actually doing. Use it to inspect the
box model, element size, and parent-child relationship.
Step 3: Check default browser styles
Before rewriting layout rules, check whether headings, paragraphs, or
lists have default margin or padding.
Step 4: Ask what should control it
Parent controls position of children
Element controls its own text and spacing
Wrapper can limit available size
Image still needs its own sizing rule
Step 5: Test the breakpoint that actually fails
Do not assume the media query is wrong. The base layout may already be
too demanding before the breakpoint.
Using Browser DevTools
DevTools allow you to inspect elements, test CSS changes, view console
errors, and monitor network requests. They are essential for debugging any
website.
DevTools = what the browser is actually doing
Check:
HTML
CSS rules
Box model
Computed values
Screen size
Panel
Description
Use Case
Elements
Shows the HTML structure and applied CSS.
Inspect layout issues or missing tags.
Styles
Displays CSS rules and allows live editing.
Test CSS changes instantly.
Console
Shows errors, warnings, and logs.
Identify JavaScript or loading errors.
Network
Monitors file requests and load times.
Check for missing files or slow assets.
Device Toolbar
Simulates different screen sizes.
Test responsive layouts.
Common HTML Issues
HTML errors often cause layout problems, broken links, or missing content.
These issues are usually easy to spot with DevTools.
HTML first
If structure is wrong
CSS cannot fix it properly
CSS bugs often relate to layout, spacing, or unexpected behaviour caused by
specificity or inheritance.
CSS debugging order
1. Is the rule applied?
2. Is it overridden?
3. Is the selector correct?
4. Is the parent controlling this?
5. Is the size causing the issue?
Issue
Description
Fix
Specificity conflicts
Styles overridden by more specific selectors.
Use DevTools to check applied rules.
Unexpected margins
Margin collapse or inherited spacing.
Inspect box model in DevTools.
Overflow issues
Content spills outside containers.
Use overflow: hidden or adjust width.
Incorrect units
Using px instead of %, rem, or vw.
Use responsive units where appropriate.
If the CSS "does nothing"
→ wrong selector
→ overridden rule
→ wrong element
→ wrong parent
Common causes:
- fixed width too large
- image too wide
- long unbroken text
- child wider than parent
Fix:
Check widths first.
Problem: horizontal scrollbar appears
Page width = screen width
But one child is wider
So page scrolls sideways
Fix:
Find the element wider than the viewport.
Problem: text or image breaks container
Ask:
- is the parent too small?
- is the child too wide?
- is width fixed when it should be flexible?
Fix:
Adjust the container/child relationship instead of hiding the issue first.
Positioning Issues
Problem: absolute positioning breaks layout
Normal flow: Absolute:
[ header ] element removed from flow
[ section ]
[ footer ]
Cause:
Absolute positioning used for layout.
Fix:
Use flexbox or grid for layout. Use absolute for decoration or special UI
cases.
Problem: element jumps unexpectedly
absolute element
looks for nearest positioned ancestor
Fix:
Check which parent is positioned.
Problem: z-index does nothing
z-index alone ≠ enough
position usually needed first
Fix:
Check whether the element is positioned.
Problem: stacking feels random
Fix:
Use small, meaningful stacking levels instead of huge random numbers.
Responsive Issues
Responsive issues occur when layouts break at certain screen sizes. DevTools
make it easier to test breakpoints and inspect how elements behave across
devices.
Desktop works
Tablet awkward
Mobile broken
This usually means:
the middle size needs a layout decision
Problem
Description
Fix
Broken at breakpoint
Styles not applying correctly at a screen size.
Check media query syntax and screen width.
Content overflow
Items too wide for the screen.
Use flexible widths and wrapping.
Text too small/large
Typography does not scale well.
Use rem, clamp(), or viewport-based units.
Images break layout
Images don't resize correctly.
Set max-width: 100% and height: auto.
Desktop: [ card ][ card ][ card ]
Tablet: [ card ][ card ]
Mobile: [ card ]
Decide what should stack, wrap, or shrink at each size.
When debugging: check the exact width where it breaks,
not just "desktop vs mobile".
Navigation Issues
Problem: nav items do not look clickable
Wrong target: li
Correct target: a
Fix:
Style the anchor, not just the list item.
Problem: nav spacing is uneven
Fix:
Use flexbox on the list container and use gap.
Problem: nav is hard to read over an image
Fix:
Adjust contrast, background, or image placement.
Real-World Issues I Hit
I centred it but nothing moved
Check whether the element is already a full-width block element. If it
fills the row, centring the box may show no visible change.
To center text inside the element, use
text-align: center;
To center the box itself, reduce its width and use auto margins
To center flex children, use the flex container
The layout is correct but still looks off
Check default browser styles before changing layout rules.
Headings often have default top and bottom margin
Lists often have default margin and padding
These defaults can make flex layouts look wrong even when flex is
working correctly
I only need one flex child aligned differently
Use
align-self
on that child. This overrides the parent's cross-axis alignment for one
item only.
My image is still too large even though the wrapper is smaller
A wrapper can limit the available space, but the image still needs its
own sizing rule. Use the wrapper to control the block width, and the
image rule to make the image respect the wrapper.
The layout breaks before my media query
The real breakpoint is where the layout actually stops fitting, not the
number you guessed first.
Check card width
Check gap
Check container width
Then adjust either the base layout or the breakpoint
My heading gets pulled into the same row as my cards
One container should not do two jobs. If a section contains a heading
and repeated cards, place the cards inside their own wrapper and apply
the row layout to that wrapper.
Same card height vs full image visibility
Show the full image: cards may end up different heights
Force equal heights: the image is often cropped
Stretching the image to fit usually causes distortion — avoid it
Fast Reminders
If it looks wrong:
→ inspect it in DevTools
If it won't move:
→ check the parent
Layout looks wrong?
→ Are items side by side or stacked?
→ If wrong → check direction
Spacing feels wrong?
→ check margin / padding / gap
Something won't move?
→ Flex must be on the parent
Image looks wrong?
→ Check the container first
Content breaking layout?
→ Something is too wide
Page scrolling sideways?
→ One element is wider than the screen
If it breaks on resize:
→ check the exact breakpoint width
If CSS does nothing:
→ check selector, specificity, and rule order
Nothing makes sense?
→ structure first → CSS second → parent → direction → size