Skip to content
engineering workbench.by StudyPort Academy
Learning path
Foundations16 minLESSON 02 / 16

Semantic HTML and why it matters

The document from the last lesson has a body. This lesson names the regions inside it. A class can change the paint, and the element name still says what the region is.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

The logs came from the article, the heading, the main element, and the link. Renaming the article in the HTML changes the first log. The script did not choose the name.

+Go deeper

The element is the name

A div and a section can look identical. The div is a generic group with no role of its own. A names the job: header, nav, main, article, section, aside, footer, or button. A page made only of divs can look finished and still announce nothing but box after box.

Regions a page needs

header introduces a page or a section. nav is a block of links. main is the primary content, and a page should have one. article is a piece that would still make sense on its own, such as a note or a story. section is a thematic group, usually with its own heading. aside is related but off to the side, such as a sidebar. footer closes a page or a section. A link in nav is still an anchor with an href. The landmark is the element, not a class called nav.

Headings name sections

An h1 names the page or the article. The next heading in that section is an h2. Choosing h4 because it looks smaller skips levels. Size belongs in CSS later. The number is the outline.

What each region element means
TagRoleHow it is used
headerIntroductory contentFor the page, or for one section
navA block of navigation linksThe links are still anchors
mainThe primary contentOne per page
articleA self-contained pieceA note or a story that could stand alone
sectionA thematic groupUsually with its own heading
asideContent beside the main ideaA sidebar or a pull quote
footerClosing contentFor the page, or for one section

Buttons are not divs

A button is in the tab order and is announced as an action. A div with a click handler is not, unless you rebuild all of that yourself. Use the button, then style it.

Read the name, then paint

If you removed every style, the regions should still be obvious from the tags. The script in the sandbox prints those tags. It is checking the HTML, not inventing a role.

04

Guided challenge

Semantic HTML and why it matters

The HTML uses an article, not a class of card. Point the script at the article element so it can read the tag, the heading, main, and the article href.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

EXPECTED CONSOLE OUTPUT

article
A self-contained article
has-main
#article

Hints 0/2

    Use all hints or make 3 failed runs (0/3).

    05

    Free sandbox

    Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.

    Opening editor…
    LIVE PREVIEW
    Console 0

    Your console output appears here.

    Saved on this deviceJavaScript · ES2022
    06

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01What makes a region navigation?
    02Why avoid skipping from h1 to h4?

    Ready to call this one understood?

    Mark this lesson complete to earn 100 XP. You can always revisit it.

    Sign in to save progress
    Next lesson