Skip to content
skillbld
HTML & CSS · 14-day planAll days
Day 13 of 14 30 min

Add the finishing touches. Position elements with relative, absolute, fixed and sticky, layer them with z-index, animate changes with transitions and transforms, and make pages that everyone can use, with visible focus, enough contrast, real buttons and respect for reduced motion.

By the end of today you can

  • Position elements with relative, absolute, fixed and sticky
  • Layer overlapping elements with z-index
  • Animate hover and focus states with transitions and transforms
  • Keep keyboard focus visible and colours readable
  • Apply an accessibility checklist to a page

Your pages have structure, style and layout. Today: the finishing touches that make a site feel polished, and the habits that make it work for everyone, including people using keyboards, screen readers or zoom.

Mind map · click a dot to fold, drag to pan

Positioning

Sketch
The CSS position values. static is the default: elements flow normally. relative nudges an element from where it would be, and makes it the reference point for absolutely positioned children. absolute takes the element out of the flow and places it relative to its nearest positioned ancestor, like a badge in a card's corner. fixed places it relative to the window, so it stays put when you scroll. sticky scrolls normally until it reaches an edge, then sticks.
index.html · edit it, the preview updates
Page preview
positionPlaced relative toTakes up space?
static (default)Normal flowYes
relativeWhere it would normally beYes (its original spot)
absoluteNearest positioned ancestorNo
fixedThe browser windowNo
stickyNormal, until it hits an edge while scrollingYes

Then use top, right, bottom, left to move it. The pattern parent relative, child absolute places badges, icons and labels in corners.

Sticky headers and z-index

index.html · edit it, the preview updates
Page preview

z-index decides which positioned element is on top when they overlap: higher wins.

Transitions and transforms

index.html · edit it, the preview updates
Page preview
  • transition: when a property changes, animate it over a duration (0.2s) with an easing (ease).
  • transform: move (translate), resize (scale), turn (rotate) without disturbing the layout. Transforms are smooth and cheap to animate.
  • Keep UI animations short: about 150–300ms.

Some people get dizzy from motion. Respect their setting:

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

Accessibility: pages for everyone

Accessibility (often written a11y) means people can use your site whatever their abilities or devices: with a keyboard only, a screen reader, zoomed text or poor eyesight. It's also good for SEO and often required by law.

Visible focus

Press Tab in the preview to move between links and buttons:

index.html · edit it, the preview updates
Page preview

Keyboard users rely on the focus outline to see where they are. Never remove it without a replacement; style it with :focus-visible, which shows it for keyboard users but not on mouse clicks.

Contrast

index.html · edit it, the preview updates
Page preview

Aim for a contrast ratio of at least 4.5:1 for normal text (3:1 for large text). DevTools and free online checkers measure it.

Accessibility checklist

Sketch
An accessibility checklist for every page. Structure: one h1, headings in order, landmarks like header, nav, main and footer. Images: meaningful alt text, or alt='' for decoration. Forms: a label for every input. Keyboard: everything reachable with Tab, visible focus, real buttons and links. Visuals: text contrast of at least 4.5 to 1, information not given by colour alone, text that can be zoomed to 200%. Motion: respect prefers-reduced-motion.
CheckUsing
Clear outline: one h1, headings in orderDay 2
Landmarks: header, nav, main, footerDay 4
Good alt text (or alt="" for decoration)Day 3
A <label> for every inputDay 5
<button> to do things, <a href> to go placesToday
Everything works with Tab and Enter, with visible focusToday
Contrast ≥ 4.5:1; colour isn't the only signalToday
Text in rem, so it zoomsDay 9
lang on <html>Day 1

Try using your own site with only the keyboard for a minute. It's eye-opening.

Recap

  • Position: relative (nudge, and a reference point), absolute (in a positioned parent), fixed (to the window), sticky (sticks while scrolling); z-index for stacking.
  • Transitions + transforms for smooth, short animations; respect reduced motion.
  • Accessibility: visible focus, enough contrast, real buttons and links, labels, alt text and a heading outline.

Tomorrow: the project, your own personal page, built and published.

Knowledge check

Test what you learned

5 questions · pick an answer to see if you're right

0/5
  1. 1

    An element has position: absolute; top: 0; right: 0;. What is it positioned relative to?

  2. 2

    What does position: sticky; top: 0; do to a header?

  3. 3

    Why should you never remove the focus outline (outline: none) without replacing it?

  4. 4

    What does transition: background-color 0.2s ease; do?

  5. 5

    Which is the accessible way to make something clickable that performs an action?

Was this lesson helpful?

Need a breather? Take a two-minute break

Keep going