← Web basics: HTML, CSS and JavaScript
Block, inline and hidden
The display property decides how a box sits on the page.
Elements have a default display type. Block elements, like <p>, <h1>, <div> and <section>, start on a new line and stretch across the full width. Inline elements, like <a>, <strong> and <span>, sit inside a line of text and are only as wide as their content. The display property changes this: display: block, display: inline, display: inline-block (sits in a line but accepts width and padding like a block), and display: none, which removes the element from the page completely.
nav a {
display: inline-block;
padding: 8px 12px;
}
.answer {
display: none;
}
.answer.shown {
display: block;
}The nav links stay side by side but get comfortable, clickable padding. Answers are hidden until something (later, JavaScript) adds the class shown.
display: none hides an element from everyone, including screen readers. visibility: hidden makes it invisible but keeps its empty space.
A <span> is the inline twin of <div>: a box with no meaning, handy for styling a few words.