DEV Community

Cover image for Day 2/365 Days coding challenge of Full stack: Add headings, paragraphs, and links in HTML
CodeWithDhanian
CodeWithDhanian

Posted on

Day 2/365 Days coding challenge of Full stack: Add headings, paragraphs, and links in HTML

Day 2: Giving Your Page Content - Headings, Paragraphs, and Links

Welcome back, future developer.

I'm Dhanian, and I'm proud of you for completing Day 1. You've built the frame of your house; today, we start putting up the walls and doors. We're moving from the abstract structure to the tangible content that users actually read and interact with.

Yesterday, we worked within the <body> tags. Today, we will fill that space with three of the most fundamental HTML elements: Headings, Paragraphs, and Links. These are the building blocks of nearly all web content.

Let's dive in.

1. Headings (<h1> to <h6>): The Chapter Titles

What they are: Headings are used to define titles and subtitles on your webpage. HTML provides six levels of headings, from <h1> (the most important) to <h6> (the least important).

What they do: Their primary job is to structure your content hierarchically, much like the table of contents in a book. This is crucial for two reasons:

  1. User Experience: It helps users quickly scan your page and understand the organization of your content.
  2. SEO (Search Engine Optimization): Search engines like Google use headings to index the structure and content of your web pages. An <h1> tag is given the most weight and should describe the main topic of the page.

The Hierarchy in Practice:
Think of it like this:

  • <h1>: The book title (you should only have one per page, ideally).
  • <h2>: The main chapter titles.
  • <h3>: Sections within a chapter.
  • <h4>, <h5>, <h6>: Subsections, as needed.

Code Snippet & Example:

<body>
  <h1>The Art of Baking</h1> <!-- Main Title -->

  <h2>Introduction to Ingredients</h2> <!-- Main Section -->

  <h3>Types of Flour</h3> <!-- Sub-section -->
  <h3>The Role of Sugar</h3> <!-- Sub-section -->

  <h2>Essential Baking Equipment</h2> <!-- Another Main Section -->

  <h3>Measuring Tools</h3> <!-- Sub-section -->
  <h4>Digital Scales vs. Measuring Cups</h4> <!-- A deeper sub-section -->
</body>
Enter fullscreen mode Exit fullscreen mode

Explanation: This creates a clear, logical content structure. A user or search engine bot can instantly see that "Digital Scales vs. Measuring Cups" is a subtopic under "Measuring Tools," which itself is part of "Essential Baking Equipment."

2. Paragraphs (<p>): The Body of Your Text

What it is: The <p> element defines a paragraph of text.

What it does: Browsers automatically add a single blank line before and after a <p> element to separate it from other content, creating readable blocks of text. This is the element you will use for the vast majority of the written content on your site.

Key Behavior: By default, text will wrap to the next line when it reaches the end of its container. Multiple spaces and line breaks within the HTML code itself are collapsed into a single space. To control breaks, you use specific tags like <br> (line break) within the paragraph.

Code Snippet & Example:

<body>
  <h1>The Benefits of Reading</h1>

  <p>Reading is a fundamental skill that opens doors to new worlds, ideas, and perspectives. It is a habit that can be cultivated for lifelong enjoyment and learning.</p> <!-- First paragraph -->

  <p>Regular reading has been shown to improve vocabulary, enhance focus and concentration, and reduce stress. It is a form of mental exercise that keeps the brain sharp and engaged.</p> <!-- Second, separate paragraph -->

  <p>This paragraph has a line break<br>right in the middle of it. See how the text continues on the next line?</p>
</body>
Enter fullscreen mode Exit fullscreen mode

Explanation: The two main ideas are separated into distinct paragraphs for readability. The third paragraph demonstrates how a <br> tag forces a line break without creating a whole new paragraph block.

3. Links (<a>): The Hyperlinks that Connect the Web

What it is: The <a> element (anchor element) is used to create hyperlinks. This is the element that makes the web a "web"—it connects pages to each other.

What it does: It allows users to click their way from one document to another, to another part of the same document, or to initiate an action like sending an email. Its most important attribute is href (hypertext reference), which defines the link's destination.

Key Attributes:

  • href="url": The path to the destination (e.g., https://google.com, about.html, #section-name).
  • target="_blank": This tells the browser to open the linked document in a new tab or window. It's crucial for directing users to external sites without navigating them away from your own.

Code Snippet & Example:

<body>
  <h1>My Favorite Resources</h1>

  <p>Exploring the web is a key part of learning to code. Here are some useful links:</p>

  <!-- Link to an external website, opens in a new tab -->
  <p>Search for anything on <a href="https://www.google.com" target="_blank">Google</a>.</p>

  <!-- Link to another page within your own website -->
  <p>Learn more <a href="about.html">about me</a>.</p>

  <!-- Link to a specific section on the same page (often used for a table of contents) -->
  <p>Jump to the <a href="#chapter2">second chapter</a> of this article.</p>
  <!-- ... lots of content ... -->
  <h2 id="chapter2">Second Chapter</h2> <!-- The 'id' here matches the link above -->
</body>
Enter fullscreen mode Exit fullscreen mode

Explanation: The first link goes to an external site and uses target="_blank" for a good user experience. The second link assumes there is a file named about.html in the same folder. The third link uses a # to jump to an element with the corresponding id on the same page.

Putting It All Together: A Simple Article

Let's combine everything we learned today into a single, cohesive HTML document.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Day 2: HTML Content</title>
</head>
<body>

    <h1>The Mighty Oak Tree</h1>

    <p>The oak tree is a symbol of strength and endurance, found in many parts of the world. There are over 500 species of oaks, and they can live for hundreds of years.</p>

    <h2>Types of Oak Trees</h2>

    <h3>White Oak</h3>
    <p>Known for its rounded lobes and light gray bark, the White Oak is a common sight in North American forests.</p>

    <h3>Red Oak</h3>
    <p>Red Oak trees have pointed lobes and produce acorns that take two years to mature. Their leaves often turn a brilliant red in the fall.</p>

    <h2>Ecological Importance</h2>
    <p>Oak trees support more life forms than any other native trees. They provide food and shelter for countless birds, insects, and mammals. Learn more about conservation efforts on the <a href="https://www.nationalwildlife.org" target="_blank">National Wildlife Federation website</a>.</p>

    <p>Back to <a href="index.html">homepage</a>.</p>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Your Day 2 Challenge:

  1. Open the index.html file you created yesterday.
  2. Replace the content inside the <body> tags. Use the example above as inspiration, but write your own short article on a topic you enjoy (e.g., your favorite hobby, a cool fact, a movie review).
  3. Must include:
    • One <h1> heading.
    • At least two <h2> headings.
    • At least one <h3> heading.
    • A paragraph under each heading.
    • At least one link to an external website (using target="_blank").
    • At least one link that would go to another page (you can create an about.html file later).
  4. Save the file and refresh your browser to see your content-rich page!

You've just learned how to create meaningful, structured, and connected content. This is huge. Keep going.

See you on Day 3.


Want a structured path through all 365 days? My ebook, "The Complete Full-Stack Developer Handbook," provides a curated curriculum, projects, and advanced insights to turn these daily lessons into true expertise.

https://codewithdhanian.gumroad.com/l/gzjvj

— Dhanian

Top comments (0)