Semantic HTML
Семантическая вёрстка
Choose HTML elements for what they mean and do: use a link to navigate, a button to perform an action, and a heading to name a section. Use CSS to decide how those elements look.
What makes HTML semantic?
A browser cannot infer that a line of bold text is a heading just because it looks like one. An <h2> conveys that meaning explicitly, even if CSS makes it the same size as the surrounding text. Semantic HTML is the practice of making that choice throughout a page: use a list for a group of items, a label for a form field, and a button for a control that performs an action.
What the browser gets from the markup
The browser builds the DOM from the HTML and uses it, along with other information, to build an accessibility tree. This gives assistive technology information such as an element's role and accessible name. A screen reader user can jump between headings or find the main content without reading every item in the navigation first.
Some native elements also come with behavior. An enabled <button> can receive focus with Tab and be activated with Enter or Space. A <div> with a click listener does not gain those features. Giving it role="button" tells assistive technology to treat it as a button, but it doesn't implement focus or keyboard activation. When a native element already does what you need, use it before reaching for ARIA.
Example: labeling a field
<form action="/search" method="get">
<label for="query">Search job listings</label>
<input id="query" name="q" type="search">
<button type="submit">Search</button>
</form>
The label's for matches the input's id, so the browser associates the visible text with the field. A screen reader can announce the field's name, and clicking the label focuses the input. The submit button sends the query to /search through standard form submission; no JavaScript is needed for that part. A placeholder alone is not a good substitute for a label: it disappears when the user types.
Common mistakes in real projects
Semantic HTML matters whether you write templates or use a component framework. A React component called Button is not automatically a button: inspect the rendered HTML to see what it actually produces. In a design system, a link and a button can look identical, but a link with href supports navigation features such as opening the destination in a new tab, while a button can submit a form or toggle a panel.
Generic containers are still useful. Use a <div> for a layout wrapper rather than turning every wrapper into a <section>. A section groups content around a topic and typically has a heading; an <article> holds a self-contained item, such as a news story. Pick heading levels to reflect the document hierarchy, not to get a particular font size.
How it comes up in interviews
You might be asked to review markup for a card with a clickable title and an icon for saving the item. Explain why the title should be a link to the detail page and the save control should be a button with an accessible name. Then describe how you would check the result: tab through the controls, activate them with the keyboard, and inspect their roles and names in the browser's accessibility tools.