Basic Interview Questions

What is HTML?

HTML (HyperText Markup Language) is the standard markup language for creating web pages. It describes the structure of a page with elements such as headings, paragraphs, links, images and forms. It is a markup language, not a programming language.

What is the difference between an element and a tag?

A tag is the markup in angle brackets: <p> (start tag) and </p> (end tag). An element is the whole thing: start tag + content + end tag, e.g. <p>Hello</p>.

What does &lt;!DOCTYPE html&gt; do?

It tells the browser the document is HTML5 and must be rendered in standards mode. Without it, browsers use "quirks mode" to imitate old browser bugs, and layouts can break.

What are void (empty) elements?

Elements that cannot have content and have no end tag: <br>, <hr>, <img>, <input>, <meta>, <link>, <source>.

Block vs inline elements?

BlockInline
starts on a new linestays in the line of text
takes the full widthtakes only the width it needs
div, p, h1, ul, sectionspan, a, img, strong, input

What is the difference between id and class?

An id must be unique in the page (one element); a class can be shared by many elements and an element can have several classes. In CSS: #id vs .class; ids have higher specificity.

Why is the alt attribute important?

It is shown when the image cannot load, read aloud by screen readers, and used by search engines to understand the image. Decorative images should have an empty alt="".