HTML Document Structure and Core Elements

Document Architecture

An HTML element comprises three core parts: the tag itself, its attributes, and the enclosed content.

<section class="primary" data-id="main-block">Web Interface</section>

The foundational boilerplate of an HTML file dictates the document's language and metadata.

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web Application</title>
</head>
<body>
    <!-- Visible content resides here -->
</body>
</html>

Body Content Elements

Text and Layout

<h1>Primary Heading</h1>  <!-- Block level, bold, distinct sizing -->
<h2>Secondary Heading</h2>
<p>Paragraph block.</p>  <!-- Block level, spacing applied -->
<div>Generic container.</div>  <!-- Block level grouping -->
<span>Inline snippet.</span>  <!-- Inline grouping for specific targeting -->
<hr>  <!-- Horizontal divider -->
<br>  <!-- Line break within text -->

Hyperlinks and Navigation

<a href="https://www.example.com" target="_blank">Visit Example</a>
<!-- target options: _self (current tab), _blank (new tab), _parent, _top -->

Page Anchors

Anchors allow intra-page jumping. Assign an id to the target element and link to it using #.

<div id="section-top">Target Destination</div>
<a href="#section-top">Return to Top</a>

For fixed positioning, such as a persistent navigation button:

<a href="#section-top" style="position:fixed; top:5px; right:5px;">Up</a>

Media Embeds

<!-- Images -->
<img src="assets/photo.jpg" alt="Descriptive text">

<!-- Inline Frames -->
<iframe src="https://www.example.org" frameborder="0" width="800" height="500" name="embed-window"></iframe>
<a href="https://www.another-site.com" target="embed-window">Load in iframe</a>

<!-- Audio -->
<audio src="media/sound.mp3" controls autoplay loop></audio>

<!-- Video -->
<video src="media/clip.mp4" controls width="640" height="360"></video>

Data Structures

Lists

<ul>
    <li>Unordered Item A</li>
    <li>Unordered Item B</li>
</ul>
<ol type="I" start="4">
    <!-- type sets numbering (1, a, A, i, I), start defines initial value -->
    <li>Ordered Item IV</li>
    <li>Ordered Item V</li>
</ol>

Tables

<table border="1" cellpadding="8" cellspacing="0">
    <thead>
        <tr> <!-- Table row -->
            <th>Heading 1</th> <!-- Bold, centered cell -->
            <th>Heading 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Data 1</td> <!-- Standard cell -->
            <td rowspan="2">Spanning two rows</td>
        </tr>
        <tr>
            <td colspan="2">Spanning two columns</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>Footer</td>
            <td>Footer</td>
        </tr>
    </tfoot>
</table>

Form Controls

<form action="/submit" method="post">
    <fieldset>
        <legend>User Details</legend>
        <label>Name: <input type="text"></label>
        <label>Password: <input type="password"></label>
        <label>Male <input type="radio" name="gender"></label>
        <label>Female <input type="radio" name="gender"></label>
        <label>Reading <input type="checkbox"></label>
        <label>Sports <input type="checkbox"></label>
        <input type="file">
        <input type="color">
        <input type="date">
        <input type="datetime-local">
        <input type="week">
        <input type="range" min="0" max="100" value="50">
        <input type="number" min="0" max="100" step="10">
        <select name="region">
            <option value="na">North America</option>
            <option value="eu">Europe</option>
            <option value="as">Asia</option>
        </select>
        <textarea cols="30" rows="5">Default text here...</textarea>
    </fieldset>
    <input type="submit" value="Send">
    <input type="reset" value="Clear">
</form>

CSS Integration Methods

Inline Styling

<div style="color: blue; background-color: lightgray;">Inline styled element</div>

Internal Stylesheet

<head>
    <style>
        .box {
            color: white;
            background-color: navy;
        }
    </style>
</head>
<body>
    <div class="box">Internal styled element</div>
</body>

External Stylesheet

<!-- Within <head> -->
<link rel="stylesheet" href="styles/main.css">

Priority order: Inline > Internal = External. When internal and external conflict, the latter defined rule overrides the former based on the cascade principle.

Profile Form Example

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>User Profile</title>
</head>
<body>
    <table border="1" cellspacing="0" cellpadding="5">
        <tr>
            <th>Full Name</th>
            <td colspan="3"><input type="text"></td>
        </tr>
        <tr>
            <th>Gender</th>
            <td><input type="radio" name="gender"> Male <input type="radio" name="gender"> Female</td>
            <th>DOB</th>
            <td><input type="date"></td>
        </tr>
        <tr>
            <th>Region</th>
            <td><select name="zone"><option>Zone A</option><option>Zone B</option></select></td>
            <th>Phone</th>
            <td><input type="tel"></td>
        </tr>
        <tr>
            <th>Interests</th>
            <td colspan="3">Tech: <input type="checkbox"> Art: <input type="checkbox"> Other: <input type="text"></td>
        </tr>
        <tr>
            <th>Bio</th>
            <td colspan="3"><textarea rows="3" cols="40"></textarea></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="Save"></td>
            <td colspan="2"><input type="reset" value="Reset"></td>
        </tr>
    </table>
</body>
</html>

Tags: html frontend web development css HTML Forms

Posted on Mon, 20 Jul 2026 16:27:34 +0000 by astropirate