Discover how to make your website footer always stay perfectly at the bottom, no matter the content!
Why Sticky footer pattern in Bootsrap? - Purpose & Use Cases
Imagine you build a website with a footer at the bottom. You want it to stay at the bottom of the page no matter how little content there is.
You try to place the footer manually by adding empty space or fixed pixel margins.
When the page content grows, the footer overlaps the content or leaves big empty gaps. You have to adjust spacing again and again for every page.
This manual spacing is slow, error-prone, and breaks on different screen sizes.
The sticky footer pattern automatically keeps the footer at the bottom of the page or screen using flexible layout techniques.
It adapts to content height and screen size without manual spacing.
<div style="min-height: 600px;">Content here</div> <footer style="position: fixed; bottom: 0; width: 100%;">Footer</footer>
<body class="d-flex flex-column min-vh-100"> <main class="flex-fill">Content here</main> <footer>Footer</footer> </body>
You can build pages where the footer always stays at the bottom, looks neat, and works well on all devices without extra effort.
Think of a blog page with little text. The sticky footer pattern keeps the footer at the bottom of the screen instead of floating awkwardly in the middle.
Manual footer placement breaks with changing content and screen sizes.
Sticky footer pattern uses flexible layout to keep footer at bottom.
It creates neat, responsive pages effortlessly.
Practice
Solution
Step 1: Understand the sticky footer concept
A sticky footer is designed to stay at the bottom of the page regardless of content height or screen size.Step 2: Compare options with the concept
Only To keep the footer visible at the bottom of the page on all screen sizes describes this behavior correctly; others describe unrelated features.Final Answer:
To keep the footer visible at the bottom of the page on all screen sizes -> Option BQuick Check:
Sticky footer = footer always at bottom [OK]
- Confusing sticky footer with fixed header
- Thinking footer hides on scroll
- Assuming footer centers content
Solution
Step 1: Identify flexbox classes for vertical layout
Bootstrap'sd-flex flex-columnmakes the body a vertical flex container, andmin-vh-100ensures full viewport height.Step 2: Check other options
Options B and C are unrelated styling classes; A fixes position but doesn't create flex layout.Final Answer:
d-flex flex-column min-vh-100 -> Option AQuick Check:
Flex column + full height = sticky footer base [OK]
- Using position-fixed instead of flexbox
- Confusing padding or text classes with layout
- Missing min-vh-100 for full height
<body class="d-flex flex-column min-vh-100"> <main class="flex-fill">Content</main> <footer class="bg-light text-center py-3">Footer</footer> </body>
What will be the visual result in the browser?
Solution
Step 1: Analyze the flexbox layout
The body is a vertical flex container with full viewport height. The main content usesflex-fillto fill available space.Step 2: Understand footer placement
The footer is placed after main and stays at the bottom because main fills space above it.Final Answer:
Footer stays at the bottom even if content is short -> Option DQuick Check:
Flex-fill main + footer after = sticky footer [OK]
- Thinking footer overlaps content
- Assuming footer scrolls away
- Confusing fixed position with flex layout
<body class="d-flex flex-column"> <main class="flex-fill">Content</main> <footer>Footer</footer> </body>
But the footer does not stick to the bottom on short pages. What is missing?
Solution
Step 1: Check body height setting
Withoutmin-vh-100, the body height is only as tall as content, so footer won't stick at bottom.Step 2: Verify other classes
Position-fixed fixes footer but not sticky footer pattern; container and text-center affect layout or style but not footer position.Final Answer:
Themin-vh-100class on the body -> Option CQuick Check:
Full viewport height needed for sticky footer [OK]
- Using position-fixed instead of flexbox height
- Adding container but missing height
- Confusing text alignment with layout
<body class="d-flex flex-column min-vh-100"> <main class="flex-fill">Content</main> <footer class="py-3 text-center">Footer</footer> </body>
Which modification achieves this?
Solution
Step 1: Understand sticky footer with background color
The sticky footer uses flexbox with full viewport height. To change background color based on page height, CSS media queries are best.Step 2: Evaluate options for responsive background
Addbg-lightfor short pages andbg-dark text-whitefor tall pages using media queries uses Bootstrap background classes with media queries to switch colors depending on viewport or content height, which is correct.Step 3: Check other options
Addbg-lightalways and use JavaScript to toggle classes on scroll uses JavaScript unnecessarily; C breaks sticky footer by fixing position; D only adds static background color.Final Answer:
Addbg-lightfor short pages andbg-dark text-whitefor tall pages using media queries -> Option AQuick Check:
Use media queries + Bootstrap bg classes for responsive footer [OK]
- Using position-fixed breaks sticky footer
- Relying on JavaScript instead of CSS
- Adding static background without responsiveness
Ready to prove it?
Pass the test and this pattern moves unknown
