skip to content

Markup & Styling

HTML, the CSS language and the tools that compile, transform or scope it, plus JSX, MDX and server templates. Interviewers start here because styling choices outlive the frameworks around them.

on this pageshow

explore

→ has its own guide

questions

414 · 2 sections

In HTML and ARIA, what is an element's accessible name, and what does the browser compute it from for `<button>Save</button>` and `<img src="logo.png" alt="Acme home">`?

level: juniorimportance: must knowfreq 60%
basics
~20 s

An element's accessible name is the short label assistive technology announces for it. The browser computes it per element type: a button's name comes from its own text content, an image's from its alt attribute.

open as a page

In HTML, what do tabindex="0", tabindex="-1", and a positive value such as tabindex="3" each do to an element?

level: juniorimportance: must knowfreq 72%
basics
~20 s

tabindex="0" puts an element in the tab order at its DOM position; a negative value such as -1 makes it focusable by script or click but never by Tab; a positive value jumps it ahead of everything else and wrecks the order.

open as a page

A toolbar button in your HTML contains only an <svg> icon and no text. What are your options for giving it an accessible name, and which would you choose?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Give the button an accessible name with aria-label="Delete", with visually hidden real text inside it, or with aria-labelledby pointing at existing on-screen text. Hide the decorative icon with aria-hidden="true" so it adds nothing. A title tooltip alone is not enough.

open as a page

In ARIA, what is the difference between aria-live="polite" and aria-live="assertive" on a live region, and which of the two do role="status" and role="alert" imply?

level: juniorimportance: must knowfreq 52%
basics
~10 s

aria-live="polite" queues the announcement until the screen reader finishes what it is saying; aria-live="assertive" interrupts immediately. role="status" implies polite, role="alert" implies assertive, and both imply aria-atomic="true".

open as a page

In web accessibility, the "first rule of ARIA use" is quoted constantly in interviews. What does the rule say, and what does following it look like in real markup?

level: juniorimportance: must knowfreq 70%
basics
~20 s

The first rule of ARIA is to not use ARIA when a native HTML element already provides the semantics and behaviour you need. Reach for button, a with href, input and label first; add ARIA only to fill real gaps.

open as a page

In the BEM CSS naming methodology, what do "block", "element" and "modifier" mean, and how does each one appear in a class name?

level: juniorimportance: must knowfreq 72%
basics
~10 s

BEM names classes after a block (a standalone component, .card), its elements (parts that exist only inside it, .card__title), and modifiers (variant flags, .card--featured). Two underscores mark an element, two hyphens mark a modifier.

open as a page

In CSS, why is a class rule such as .title { color: red } described as living in a global namespace, and what problems does that create in a large codebase?

level: juniorimportance: must knowfreq 55%
basics
~20 s

CSS selectors are matched against the entire document regardless of which file they were written in, so one .title rule styles every element with that class. Collisions are silent, and unrelated components end up restyling each other.

open as a page

Most CSS style guides tell you to style a component with a single class like `.card__title` instead of a chain like `#main .card h2`. Both match the same heading — what does the flat single-class convention buy a growing codebase?

level: juniorimportance: must knowfreq 62%
basics
~20 s

A single class keeps every rule at the same low weight, so a later rule can override it by source order alone. IDs and long descendant chains raise the weight, forcing every future override to be heavier still.

open as a page

In CSS architecture, what does a "utility-first" approach mean compared with writing semantic component classes, and what trade do the two make against each other?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Utility-first composes many single-purpose classes in the markup, each setting one or two declarations. The semantic approach puts one meaning-based class on the element and defines all its styling in the stylesheet. The trade is markup noise versus an ever-growing stylesheet.

open as a page

In CSS, an element has `width: 100px`, `padding: 20px`, and `border: 2px solid`. How wide does it actually render under the default `box-sizing`, and what changes if you set `box-sizing: border-box`?

level: juniorimportance: must knowfreq 88%
basics
~20 s

Under the default box-sizing: content-box, width sizes only the content box, so 100px width plus 20px padding on each side plus 2px borders renders 144px wide. With box-sizing: border-box the box stays 100px and the content area shrinks to 56px.

open as a page