HTML & CSS flashcards: layout, cascade and accessibility
Fifty HTML and CSS cards: semantic HTML and accessible forms, specificity and cascade layers, flexbox and grid, stacking contexts and z-index, modern units and container queries.
Practice now
Study without an account
<nav>, <main> and <article>?Scheduled with the default Askesis timings. Progress is saved in this browser.
All 50 cards
- 1Why use semantic elements like
<nav>,<main>and<article>?They tell browsers, screen readers and search engines what each part of the page is, for free - 2
<article>vs<section><article>is self-contained and could stand alone;<section>groups related content, usually with a heading - 3How many visible
<main>elements can a page have?One, and it must not sit inside<article>,<aside>,<header>,<footer>or<nav> - 4
<button>vs<a>A button performs an action; a link navigates. A clickable<div>is neither focusable nor announced correctly - 5What is the default
typeof a<button>inside a form?submit; usetype="button"for buttons that shouldn’t submit - 6Connect a label to an inputhtml
<label for="email">Email</label> <input id="email" type="email" />Wrapping the input inside the<label>works too. - 7What should
altcontain?A description of what the image conveys; usealt=""for purely decorative images - 8The first rule of ARIAUse a native HTML element with the behavior you need before adding ARIA roles or attributes
- 9
aria-labelvsaria-labelledbyaria-labelgives a text label directly;aria-labelledbypoints to the ID of visible text that labels the element - 10What does
aria-live="polite"do?Screen readers announce changes inside the element when the user is idle - 11
tabindex="0"vstabindex="-1"0adds the element to the Tab order;-1makes it focusable only from script. Avoid positive values - 12The CSS box model, inside outContent, padding, border, margin
- 13What does
box-sizing: border-boxchange?widthandheightinclude padding and border, so adding padding doesn’t grow the box - 14What is margin collapsing?Adjacent vertical margins of block elements merge into the larger one; it doesn’t happen between flex or grid items
- 15Specificity order, highest firstInline styles › IDs › classes, attributes and pseudo-classes › elements and pseudo-elements
- 16Specificity of
#nav .item a(1, 1, 1): one ID, one class, one element - 17How do cascade layers decide which rule wins?Later layers beat earlier ones regardless of specificity, and unlayered styles beat all layerscss
@layer reset, base, components; @layer base { a { color: blue } } - 18
:is()vs:where()Both match any selector in their list;:where()has zero specificity,:is()takes its most specific argument - 19What does
:has()select?An element that contains (or is followed by) a match, e.g..card:has(img)is a card with an image - 20
:focusvs:focus-visible:focus-visibleonly matches when the browser would show a focus ring, typically for keyboard users, not mouse clicks - 21Flexbox vs gridFlexbox lays out items along one axis; grid lays out rows and columns at the same time
- 22Center a child horizontally and verticallycss
.parent { display: grid; place-items: center; }With flexbox:justify-content: center; align-items: center;. - 23What is
flex: 1short for?flex-grow: 1; flex-shrink: 1; flex-basis: 0 - 24In a flex row, what do
justify-contentandalign-itemscontrol?justify-contentthe main (horizontal) axis;align-itemsthe cross (vertical) axis - 25What does
gapdo?Adds space between flex or grid items without margins on the outer edges - 26What is the
frunit?A share of the free space in a grid containercssgrid-template-columns: 200px 1fr 2fr; - 27A responsive card grid without media queriescss
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); - 28
auto-fillvsauto-fitauto-fillkeeps empty tracks;auto-fitcollapses them so the items stretch to fill the row - 29What is an absolutely positioned element positioned against?Its nearest ancestor with a
positionother thanstatic(or the initial containing block) - 30Why might
position: stickydo nothing?It sticks within its nearest scrolling ancestor; an ancestor withoverflow: hiddenorautobecomes that scroller - 31When is a
position: fixedelement not fixed to the viewport?When an ancestor hastransform,filter,backdrop-filterorperspective; that ancestor becomes its containing block - 32Why doesn’t
z-index: 9999bring my element to the front?z-index only competes inside one stacking context; if an ancestor forms a context, the element can’t rise above that ancestor’s siblings - 33What creates a stacking context?For example: a positioned element with a
z-index,position: fixedorsticky,opacitybelow 1,transform,filter,isolation: isolate - 34What does
isolation: isolatedo?Creates a new stacking context and nothing else, to contain z-indexes inside a component - 35Does
z-indexwork on aposition: staticelement?No, except on flex and grid items - 36What is the top layer?Where modal
<dialog>s (showModal()) and popovers render: above everything, whatever the z-index - 37
remvsemremis relative to the root font size;emto the element’s own font size (the parent’s, forfont-sizeitself) - 38
100vhvs100dvhon phonesvhuses the largest viewport and ignores the browser’s toolbars;dvhfollows the visible area as toolbars appear and hidesvhandlvhare the smallest and largest viewport sizes. - 39Media query with range syntaxcss
@media (width >= 768px) { .sidebar { display: block; } } - 40Container queryStyle an element by the size of its container instead of the viewportcss
.list { container-type: inline-size; } @container (min-width: 400px) { .card { display: grid; } } - 41Custom property with a fallbackcss
:root { --accent: #c6f432; } .btn { background: var(--accent, gold); }Custom properties inherit and can change at runtime. - 42What are logical properties?Direction-aware properties like
margin-inline-startandpadding-blockthat follow the writing direction (left-to-right or right-to-left) - 43
transitionvsanimationA transition animates between two states when a property changes; an animation runs@keyframesand can start on its own and loop - 44Respect users who prefer less motioncss
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } } - 45Which properties animate most smoothly?
transformandopacity; they can run on the compositor without recalculating layout - 46What does
color-scheme: light darkdo?Declares that the page supports both themes, so form controls, scrollbars andlight-dark()follow the user’s setting - 47What does
light-dark()do?Picks the first color in a light color scheme and the second in a dark onecss:root { color-scheme: light dark; } body { color: light-dark(#111, #eee); } - 48What does
aspect-ratiodo?Keeps a box’s width-to-height ratiocss.thumb { aspect-ratio: 16 / 9; width: 100%; } - 49Clamp a font size between a minimum and maximumcss
h1 { font-size: clamp(1.75rem, 4vw, 3rem); } - 50Visually hide text but keep it for screen readersClip it to 1 px and position it absolutely (an “sr-only” class);
display: nonewould hide it from screen readers too
Frequently asked questions
Is this deck for beginners?
Yes. It starts with the basics like the box model and semantic elements, then covers modern CSS.
Why is my z-index not working?
Usually an ancestor creates a stacking context. The cards on stacking contexts and isolation explain how to fix it.
Do the newer features work in all browsers?
Container queries, :has(), dvh and light-dark() work in current versions of all major browsers.
More in Web development
React
Fifty React cards: state and re-rendering, useEffect and cleanup, memoization, refs, context, Suspense and the React 19 APIs like use, useOptimistic and useActionState.
50 cardsVue
Vue 3 fundamentals: ref vs reactive, computed and watch, props and emits, v-model, directives, slots, single-file components and Pinia stores.
50 cardsAngular
Modern Angular: standalone components, signals, inputs and outputs, dependency injection, RxJS basics, @if and @for, routing and OnPush change detection.
50 cardsNext.js
Next.js App Router basics: server vs client components, layouts, route handlers, server actions, caching, metadata, dynamic routes and middleware.
50 cardsNode.js
Node.js fundamentals: the event loop, ESM vs CommonJS, npm, streams, Buffer, fs/promises, process, error handling, worker threads and a basic HTTP server.
50 cardsGraphQL
GraphQL basics: schema types, queries, mutations, subscriptions, resolvers, variables, fragments, N+1 and DataLoader, introspection and GraphQL vs REST.
50 cards