Skip to content

HTML Headings

Headings are crucial for structuring web content and improving accessibility.

Headings are defined using the

through

tags.

represents the most important heading (usually the main title of the page), while

represents the least important heading.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings Example</title>
</head>
<body>
<h1>Main Page Title (Most Important)</h1>
<p>This paragraph introduces the main topic.</p>
<h2>Section Title (Sub-heading)</h2>
<p>This paragraph belongs to the first section.</p>
<h3>Subsection Title (Less Important)</h3>
<p>More specific details within the section.</p>
<h2>Another Section Title</h2>
<p>This paragraph starts a new major section.</p>
</body>
</html>

Note: Browsers typically render headings with default styling (like larger font sizes and margins), but you should rely on CSS for precise visual control.

Use headings strictly for titling sections and structuring your content. Avoid using heading tags simply to make text look big or bold; use CSS for styling.

  • SEO: Search engines use headings to understand the structure and key topics of your page.
  • Accessibility: Screen readers use headings to help users navigate the page content quickly. A logical heading structure (

    followed by

    , then

    , etc., without skipping levels) is essential.

  • Readability: Users often scan headings to find the information they need. Clear headings improve user experience.

Best Practice: Use only one

per page for the main title. Structure the rest of your content logically using

through

, ensuring you don’t skip heading levels (e.g., don’t jump from an

to an

).

The


tag represents a thematic break between paragraph-level elements. It’s often rendered as a horizontal line by default, but its semantic meaning is a shift in topic.

Use


to indicate a change in topic within a section, not just for decorative lines. Use CSS borders for purely visual dividers.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HR Example</title>
</head>
<body>
<p>This paragraph discusses the first topic.</p>
<hr>
<p>This paragraph discusses a related but distinct second topic.</p>
</body>
</html>

The element is a container for metadata (data about the HTML document) and is not displayed directly on the web page itself. It contains essential information for the browser and search engines.

It is placed between the tag and the tag.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"> <!-- Specifies the character encoding for the document -->
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Configures the viewport for responsive design -->
<title>Document Title</title> <!-- Sets the title shown in the browser tab/window -->
<link rel="stylesheet" href="styles.css"> <!-- Links to external CSS files -->
<script src="script.js" defer></script> <!-- Links to external JavaScript files -->
<!-- Other meta tags (description, keywords), favicons, etc. can go here -->
</head>
<body>
<!-- Visible page content goes here -->
<p>Hello World!</p>
</body>
</html>
  • <title>: Defines the document’s title displayed in the browser’s title bar or tab. Crucial for SEO and accessibility.
  • <meta>: Provides metadata like character set (charset), viewport settings, page description, keywords, author.
  • <link>: Used to link external resources, most commonly CSS stylesheets.
  • <style>: Contains internal CSS styles (less common for larger projects, external stylesheets are preferred).
  • <script>: Links to or contains JavaScript code.

Ever wonder how a web page is built? You can view the HTML source code of any page.

Most modern browsers allow you to view the source by right-clicking on the page and selecting an option like “View Page Source” or by using the browser’s developer tools (often accessed by pressing F12). Developer tools provide a more interactive way to inspect HTML, CSS, and JavaScript.

This section briefly reviewed some fundamental HTML structural and metadata tags.

TagDescription
The root element of an HTML page.
Contains meta-information about the HTML document.
Specifies the title for the document (shown in browser tabs).
Provides metadata like character set, viewport, description.
Contains the visible page content.

to

Define HTML headings for structure and hierarchy.

Represents a thematic break between content.